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

Pass args to generate_magic_command() to allow testing.

This commit is contained in:
philippeitis
2020-03-08 13:26:15 -07:00
committed by GitHub
parent eab2f4b056
commit a032ae56ae

View File

@ -183,18 +183,18 @@ def json_out(data, pretty=False):
print(json.dumps(data)) print(json.dumps(data))
def generate_magic_command(): def generate_magic_command(args):
""" """
Returns a tuple with a boolean and a command, where the boolean signifies that Returns a tuple with a boolean and a command, where the boolean signifies that
the command is valid, and the command is either a command string or None. the command is valid, and the command is either a command string or None.
""" """
# Parse with magic syntax: jc -p ls -al # Parse with magic syntax: jc -p ls -al
if len(sys.argv) <= 1 or sys.argv[1].startswith('--'): if len(args) <= 1 or args[1].startswith('--'):
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, sys.argv[1:])).split() args_given = " ".join(map(shlex.quote, args[1:])).split()
options = [] options = []
# find the options # find the options
@ -242,7 +242,7 @@ def generate_magic_command():
def magic(): def magic():
valid_command, run_command = generate_magic_command() valid_command, run_command = generate_magic_command(sys.argv)
if valid_command: if valid_command:
os.system(run_command) os.system(run_command)
exit() exit()