From 8e02e5c75a11cf205299ee6f87b67f9b787cf55e Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 11 Mar 2020 09:21:14 -0700 Subject: [PATCH] fix issue with getting options with some commands #47 --- jc/cli.py | 8 +++----- tests/test_cli.py | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/jc/cli.py b/jc/cli.py index f996563d..c7bf174a 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -198,20 +198,18 @@ def generate_magic_command(args): return False, None # correctly parse escape characters and spaces with shlex - args_given = " ".join(map(shlex.quote, args[1:])).split() + args_given = ' '.join(map(shlex.quote, args[1:])).split() options = [] # find the options - popped = 0 - for i, arg in enumerate(args_given): + for arg in list(args_given): # parser found - use standard syntax if arg.startswith('--'): return False, None # option found - populate option list elif arg.startswith('-'): - options.append(args_given.pop(i - popped)[1:]) - popped += 1 + options.extend(args_given.pop(0)[1:]) # command found if iterator didn't already stop - stop iterating else: diff --git a/tests/test_cli.py b/tests/test_cli.py index fdd768da..d1a3a7d8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -13,6 +13,9 @@ class MyTests(unittest.TestCase): 'jc -p pip3 show jc': 'pip3 show jc | jc --pip-show -p', 'jc -prd last': 'last | jc --last -prd', 'jc -prd lastb': 'lastb | jc --last -prd', + 'jc -p airport -I': 'airport -I | jc --airport -p', + 'jc -p -r airport -I': 'airport -I | jc --airport -pr', + 'jc -prd airport -I': 'airport -I | jc --airport -prd', 'jc -p nonexistent command': 'nonexistent command', 'jc -ap': None }