Skip to content
Snippets Groups Projects
Commit 3f77f2bf authored by Eva Schiffer's avatar Eva Schiffer
Browse files

update to clean up argparse use

parent bb98c242
No related branches found
No related tags found
No related merge requests found
...@@ -1287,25 +1287,8 @@ def inspect_stats_library_call (afn, var_list=None, options_set=None, do_documen ...@@ -1287,25 +1287,8 @@ def inspect_stats_library_call (afn, var_list=None, options_set=None, do_documen
def main(): def main():
# get our command line argument handling set up # horray, dummy options!
options = config_organizer.parse_arguments() options = None
args = options.misc
if options.self_test:
import doctest
doctest.testmod()
sys.exit(2)
# set up the logging level based on the options the user selected on the command line
lvl = logging.WARNING
if options.debug: lvl = logging.DEBUG
elif options.verbose: lvl = logging.INFO
elif options.quiet: lvl = logging.ERROR
logging.basicConfig(level = lvl)
# display the version
if options.version :
print (get_glance_version_string() + '\n')
commands = {} commands = {}
prior = None prior = None
...@@ -1879,10 +1862,29 @@ def main(): ...@@ -1879,10 +1862,29 @@ def main():
# lowercase locals # lowercase locals
# Future: this is an awkward use and could be made more elegant # Future: this is an awkward use and could be made more elegant
lower_locals = { } lower_locals = {}
for command_key in commands : for command_key in commands:
lower_locals[command_key.lower()] = locals()[command_key] lower_locals[command_key.lower()] = locals()[command_key]
# get our command line argument handling set up
options = config_organizer.parse_arguments(get_glance_version_string(), list(lower_locals.keys()), )
args = options.misc
if options.self_test:
import doctest
doctest.testmod()
sys.exit(2)
# set up the logging level based on the options the user selected on the command line
lvl = logging.WARNING
if options.debug:
lvl = logging.DEBUG
elif options.verbose:
lvl = logging.INFO
elif options.quiet:
lvl = logging.ERROR
logging.basicConfig(level=lvl)
# if what the user asked for is not one of our existing functions, print the help # if what the user asked for is not one of our existing functions, print the help
to_return = 0 to_return = 0
if (options.command == "") or (options.command not in lower_locals): if (options.command == "") or (options.command not in lower_locals):
......
...@@ -435,7 +435,7 @@ def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) : ...@@ -435,7 +435,7 @@ def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) :
return paths, runInfo, defaultsToUse, requestedNames, usedConfigFile return paths, runInfo, defaultsToUse, requestedNames, usedConfigFile
def parse_arguments () : def parse_arguments (version_string, commands_list, ) :
""" """
Parse command line options and return an options object Parse command line options and return an options object
...@@ -505,8 +505,8 @@ def parse_arguments () : ...@@ -505,8 +505,8 @@ def parse_arguments () :
parser.add_argument('-w', '--debug', dest="debug", parser.add_argument('-w', '--debug', dest="debug",
action="store_true", default=False, action="store_true", default=False,
help="enable logging of debug output (warning: this will generate far more messages)") help="enable logging of debug output (warning: this will generate far more messages)")
parser.add_argument('-n', '--version', dest='version', parser.add_argument('-n', '--version', version=version_string, action="version",
action="store_true", default=False, help="print the Glance version") help="print the Glance version")
# data options for setting variable defaults # data options for setting variable defaults
parser.add_argument('-e', '--epsilon', dest=EPSILON_KEY, type=float, default=0.0, parser.add_argument('-e', '--epsilon', dest=EPSILON_KEY, type=float, default=0.0,
...@@ -556,7 +556,7 @@ def parse_arguments () : ...@@ -556,7 +556,7 @@ def parse_arguments () :
help="format output to be programmatically parsed. (only affects 'info')") help="format output to be programmatically parsed. (only affects 'info')")
# get the command # get the command
parser.add_argument('command', metavar="COMMAND", help="command to invoke", type=str.lower) parser.add_argument('command', metavar="COMMAND", choices=commands_list, help="command to invoke", type=str.lower)
parser.add_argument('misc', metavar='[FILE [VARIABLE]]+', nargs='*') parser.add_argument('misc', metavar='[FILE [VARIABLE]]+', nargs='*')
# options.misc is expected to catch the COMMAND and FILE and VARIABLE # options.misc is expected to catch the COMMAND and FILE and VARIABLE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment