From bb98c2423842ae164f2232e57cdb7f061eaf1a44 Mon Sep 17 00:00:00 2001 From: Eva Schiffer <evas@ssec.wisc.edu> Date: Tue, 24 Aug 2021 14:30:33 -0500 Subject: [PATCH] changing how argparse handles the command --- pyglance/glance/compare.py | 4 ++-- pyglance/glance/config_organizer.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py index c90aeaf..783daf6 100644 --- a/pyglance/glance/compare.py +++ b/pyglance/glance/compare.py @@ -1885,7 +1885,7 @@ def main(): # if what the user asked for is not one of our existing functions, print the help to_return = 0 - if (not args) or (args[0].lower() not in lower_locals): + if (options.command == "") or (options.command not in lower_locals): if options.version: to_return = 0 else : @@ -1894,7 +1894,7 @@ def main(): to_return = 9 else: # call the function the user named, given the arguments from the command line, lowercase the request to ignore case - return_code = lower_locals[args[0].lower()](*args[1:]) + return_code = lower_locals[options.command](*args) to_return = 0 if return_code is None else return_code LOG.debug("Glance run complete, returning code: " + str(to_return)) diff --git a/pyglance/glance/config_organizer.py b/pyglance/glance/config_organizer.py index bc74390..ad340c2 100644 --- a/pyglance/glance/config_organizer.py +++ b/pyglance/glance/config_organizer.py @@ -555,7 +555,9 @@ def parse_arguments () : action="store_true", default=False, help="format output to be programmatically parsed. (only affects 'info')") - parser.add_argument('misc', metavar='COMMAND [FILE [VARIABLE]]+', nargs='*') + # get the command + parser.add_argument('command', metavar="COMMAND", help="command to invoke", type=str.lower) + parser.add_argument('misc', metavar='[FILE [VARIABLE]]+', nargs='*') # options.misc is expected to catch the COMMAND and FILE and VARIABLE # arguments. Unfortunately, argparse expects all of these arguments -- GitLab