Skip to content

Commit

Permalink
Fix a bug where a request for help wasn't detected.
Browse files Browse the repository at this point in the history
Testing Done:
options unittests pass.

Reviewed at https://rbcommons.com/s/twitter/r/1467/
  • Loading branch information
benjyw authored and Benjy committed Dec 11, 2014
1 parent fdd9a4e commit af07ba6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/python/pants/option/arg_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class ArgSplitter(object):
Handles help flags (-h, --help and the scope 'help') specially.
"""
_HELP_FLAGS = ('-h', '--help')

def __init__(self, known_scopes):
self._known_scopes = set(known_scopes + ['help'])
self._unconsumed_args = [] # In reverse order, for efficient popping off the end.
Expand Down Expand Up @@ -115,9 +117,11 @@ def assign_flag_to_scope(flag, default_scope):
while self._unconsumed_args and not self._at_double_dash():
arg = self._unconsumed_args.pop()
if arg.startswith(b'-'):
# During migration we allow flags here, and assume they are in global scope.
# TODO(benjy): Should we allow this even after migration?
assign_flag_to_scope(arg, GLOBAL_SCOPE)
# We assume any args here are in global scope.
if arg in self._HELP_FLAGS:
self._is_help = True
else:
assign_flag_to_scope(arg, GLOBAL_SCOPE)
else:
targets.append(arg)

Expand Down Expand Up @@ -154,7 +158,7 @@ def _consume_flags(self):
flags = []
while self._at_flag():
flag = self._unconsumed_args.pop()
if flag in ('-h', '--help'):
if flag in self._HELP_FLAGS:
self._is_help = True
else:
flags.append(flag)
Expand Down
2 changes: 2 additions & 0 deletions tests/python/pants_test/option/test_arg_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ def test_help_detection(self):
{'': [], 'compile': []}, [], [], expected_is_help=True)
self._split('./pants compile --help test', ['compile', 'test'],
{'': [], 'compile': [], 'test': []}, [], [], expected_is_help=True)
self._split('./pants test src/foo/bar:baz -h', ['test'],
{'': [], 'test': []}, ['src/foo/bar:baz'], [], expected_is_help=True)

0 comments on commit af07ba6

Please sign in to comment.