1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

fix issue with getting options with some commands #47

This commit is contained in:
Kelly Brazil
2020-03-11 09:21:14 -07:00
parent 970493ab93
commit 8e02e5c75a
2 changed files with 6 additions and 5 deletions

View File

@ -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:

View File

@ -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
}