Skip to content

Commit

Permalink
Validate that registered args begin with dashes, as appropriate.
Browse files Browse the repository at this point in the history
Otherwise we get a cryptic error further along.

Testing Done:
CI baking. Verified that bad registration triggers these validation checks.

Reviewed at https://rbcommons.com/s/twitter/r/1211/
  • Loading branch information
benjyw authored and Benjy committed Oct 24, 2014
1 parent b92d5d4 commit 8d21e71
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/python/pants/option/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,17 @@ def _register_boolean(self, dest, args, kwargs, inverse_args, inverse_kwargs):

def _validate(self, args, kwargs):
"""Ensure that the caller isn't trying to use unsupported argparse features."""
for arg in args:
if not arg.startswith('-'):
raise RegistrationError('Option {0} in scope {1} must begin '
'with a dash.'.format(arg, self._scope))
if not arg.startswith('--') and len(arg) > 2:
raise RegistrationError('Multicharacter option {0} in scope {1} must begin '
'with a double-dash'.format(arg, self._scope))
for k in ['nargs', 'required']:
if k in kwargs:
raise RegistrationError('%s unsupported in registration of option %s.' % (k, args))
raise RegistrationError('{0} unsupported in registration of option {1} in '
'scope {2}.'.format(k, args, self._scope))

def _set_dest(self, args, kwargs, legacy_dest):
"""Maps the externally-used dest to a scoped one only seen internally.
Expand Down

0 comments on commit 8d21e71

Please sign in to comment.