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:
@ -198,20 +198,18 @@ def generate_magic_command(args):
|
|||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
# correctly parse escape characters and spaces with shlex
|
# 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 = []
|
options = []
|
||||||
|
|
||||||
# find the options
|
# find the options
|
||||||
popped = 0
|
for arg in list(args_given):
|
||||||
for i, arg in enumerate(args_given):
|
|
||||||
# parser found - use standard syntax
|
# parser found - use standard syntax
|
||||||
if arg.startswith('--'):
|
if arg.startswith('--'):
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
# option found - populate option list
|
# option found - populate option list
|
||||||
elif arg.startswith('-'):
|
elif arg.startswith('-'):
|
||||||
options.append(args_given.pop(i - popped)[1:])
|
options.extend(args_given.pop(0)[1:])
|
||||||
popped += 1
|
|
||||||
|
|
||||||
# command found if iterator didn't already stop - stop iterating
|
# command found if iterator didn't already stop - stop iterating
|
||||||
else:
|
else:
|
||||||
|
@ -13,6 +13,9 @@ class MyTests(unittest.TestCase):
|
|||||||
'jc -p pip3 show jc': 'pip3 show jc | jc --pip-show -p',
|
'jc -p pip3 show jc': 'pip3 show jc | jc --pip-show -p',
|
||||||
'jc -prd last': 'last | jc --last -prd',
|
'jc -prd last': 'last | jc --last -prd',
|
||||||
'jc -prd lastb': 'lastb | 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 -p nonexistent command': 'nonexistent command',
|
||||||
'jc -ap': None
|
'jc -ap': None
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user