Fixed argparse hack to allow 'atrcopy image COMMAND --help'

This commit is contained in:
Rob McMullen 2017-05-02 21:26:28 -07:00
parent aa8e6f70a8
commit b0ac658749

View File

@ -339,24 +339,30 @@ def run():
found_help = -1 found_help = -1
first_non_dash = 0 first_non_dash = 0
num_non_dash = 0 num_non_dash = 0
for i in range(len(args)): non_dash = []
if args[i].startswith("-"): for i, arg in enumerate(args):
if arg.startswith("-"):
if i == 0: if i == 0:
first_non_dash = -1 first_non_dash = -1
if args[i] =="-h" or args[i] == "--help": if arg =="-h" or arg == "--help":
found_help = i found_help = i
else: else:
num_non_dash += 1 num_non_dash += 1
non_dash.append(arg)
if first_non_dash < 0: if first_non_dash < 0:
first_non_dash = i first_non_dash = i
if found_help >= 0 or first_non_dash < 0: if found_help >= 0 or first_non_dash < 0:
if found_help == 0 or first_non_dash < 0: if found_help == 0 or first_non_dash < 0:
# put dummy argument so help for entire script will be shown # put dummy argument so help for entire script will be shown
args = ["--help"] args = ["--help"]
elif args[first_non_dash] in command_aliases or args[first_non_dash] in reverse_aliases: elif non_dash[0] in command_aliases or non_dash[0] in reverse_aliases:
# if the first argument without a leading dash looks like a # if the first argument without a leading dash looks like a
# command instead of a disk image, show help for that command # command instead of a disk image, show help for that command
args = [args[first_non_dash], "--help"] args = [non_dash[0], "--help"]
elif len(non_dash) > 0 and (non_dash[1] in command_aliases or non_dash[1] in reverse_aliases):
# if the first argument without a leading dash looks like a
# command instead of a disk image, show help for that command
args = [non_dash[1], "--help"]
else: else:
# show script help # show script help
args = ["--help"] args = ["--help"]