diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py index 783daf6fd2e4abd80f698bff46d96511a13276ba..f7ff4593dbc19eacd6970257316583d27e208250 100644 --- a/pyglance/glance/compare.py +++ b/pyglance/glance/compare.py @@ -1287,25 +1287,8 @@ def inspect_stats_library_call (afn, var_list=None, options_set=None, do_documen def main(): - # get our command line argument handling set up - options = config_organizer.parse_arguments() - 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') + # horray, dummy options! + options = None commands = {} prior = None @@ -1879,10 +1862,29 @@ def main(): # lowercase locals # Future: this is an awkward use and could be made more elegant - lower_locals = { } - for command_key in commands : + lower_locals = {} + for command_key in commands: 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 to_return = 0 if (options.command == "") or (options.command not in lower_locals): diff --git a/pyglance/glance/config_organizer.py b/pyglance/glance/config_organizer.py index ad340c2faf42e53dd28a94fa3407add9e0e42f1d..c5b62e6e2a1a1e20d0e57a180294adbedbc90f4f 100644 --- a/pyglance/glance/config_organizer.py +++ b/pyglance/glance/config_organizer.py @@ -435,7 +435,7 @@ def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) : 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 @@ -505,8 +505,8 @@ def parse_arguments () : parser.add_argument('-w', '--debug', dest="debug", action="store_true", default=False, help="enable logging of debug output (warning: this will generate far more messages)") - parser.add_argument('-n', '--version', dest='version', - action="store_true", default=False, help="print the Glance version") + parser.add_argument('-n', '--version', version=version_string, action="version", + help="print the Glance version") # data options for setting variable defaults parser.add_argument('-e', '--epsilon', dest=EPSILON_KEY, type=float, default=0.0, @@ -556,7 +556,7 @@ def parse_arguments () : help="format output to be programmatically parsed. (only affects 'info')") # 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='*') # options.misc is expected to catch the COMMAND and FILE and VARIABLE