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 }