From a032ae56ae7d247e00415267b65b2a8b80a3302e Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Sun, 8 Mar 2020 13:26:15 -0700 Subject: [PATCH] Pass args to generate_magic_command() to allow testing. --- jc/cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jc/cli.py b/jc/cli.py index aebf829b..fda0d106 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -183,18 +183,18 @@ def json_out(data, pretty=False): 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 the command is valid, and the command is either a command string or None. """ # 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 # 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 = [] # find the options @@ -242,7 +242,7 @@ def generate_magic_command(): def magic(): - valid_command, run_command = generate_magic_command() + valid_command, run_command = generate_magic_command(sys.argv) if valid_command: os.system(run_command) exit()