diff --git a/jc/cli.py b/jc/cli.py index 5675fb3b..85346f35 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -430,8 +430,9 @@ Examples: else: break - # if -h, -a, or -v found in options, then bail out + # if -h, -a, or -v found in options, then clear options and bail out if 'h' in self.magic_options or 'a' in self.magic_options or 'v' in self.magic_options: + self.magic_options = [] return # all options popped and no command found - for case like 'jc -x' @@ -538,9 +539,8 @@ Examples: self.args = sys.argv self.magic_parser() - # set magic options if magic syntax was found - if self.magic_found_parser: - self.options.extend(self.magic_options) + # add magic options to regular options + self.options.extend(self.magic_options) # find options if magic_parser did not find a command if not self.magic_found_parser: diff --git a/tests/test_jc_cli.py b/tests/test_jc_cli.py index 7bac6eac..96c106f8 100644 --- a/tests/test_jc_cli.py +++ b/tests/test_jc_cli.py @@ -20,16 +20,16 @@ class MyTests(unittest.TestCase): 'jc -p -r airport -I': ('--airport', ['p', 'r'], ['airport', '-I']), 'jc -prd airport -I': ('--airport', ['p', 'r', 'd'], ['airport', '-I']), 'jc -p nonexistent command': (None, ['p'], ['nonexistent', 'command']), - 'jc -ap': (None, ['a', 'p'], None), - 'jc -a arp -a': (None, ['a'], None), - 'jc -v': (None, ['v'], None), - 'jc -h': (None, ['h'], None), + 'jc -ap': (None, [], None), + 'jc -a arp -a': (None, [], None), + 'jc -v': (None, [], None), + 'jc -h': (None, [], None), 'jc -h --arp': (None, ['h'], None), - 'jc -h arp': (None, ['h'], None), - 'jc -h arp -a': (None, ['h'], None), + 'jc -h arp': (None, [], None), + 'jc -h arp -a': (None, [], None), 'jc --pretty dig': ('--dig', ['p'], ['dig']), 'jc --pretty --monochrome --quiet --raw dig': ('--dig', ['p', 'm', 'q', 'r'], ['dig']), - 'jc --about --yaml-out': (None, ['a', 'y'], None) + 'jc --about --yaml-out': (None, [], None) } for command, expected in commands.items():