From 82276beabd2b2cd81b333199e24136421bca7580 Mon Sep 17 00:00:00 2001
From: Eva Schiffer <evas@ssec.wisc.edu>
Date: Wed, 25 Aug 2021 11:33:49 -0500
Subject: [PATCH] cleaning up how our helptext is printed

---
 pyglance/glance/compare.py          | 30 +++++++++++++++++++++--------
 pyglance/glance/config_organizer.py |  4 ++--
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py
index f7ff459..fd149dd 100644
--- a/pyglance/glance/compare.py
+++ b/pyglance/glance/compare.py
@@ -48,6 +48,19 @@ from glance.gui_constants import A_CONST, B_CONST
 
 LOG = logging.getLogger(__name__)
 
+def _get_all_commands_help_string (commands_dict, ) :
+    """
+    given the dictonary of commands, compose the string with brief information about all of them
+    """
+
+    to_return = "Available commands in Glance:\n"
+
+    for command_name in commands_dict :
+        short_desc = commands_dict[command_name].__doc__.split('\n')[0]
+        to_return += "\t%-16s %s\n" % (command_name, short_desc)
+
+    return to_return
+
 def _get_possible_files_from_dir (dir_path) :
     """given a path to a directory, return all the paths to files we think we can open in that directory
 
@@ -1829,7 +1842,11 @@ def main():
 
     def help(command=None):
         """print help for a specific command or list of commands
-        e.g. help stats
+        print help for a specific command or list of commands
+
+        Examples:
+             glance help stats
+             glance help report
         """
 
         print_all_summary = False
@@ -1850,12 +1867,7 @@ def main():
 
         # print out a list of summaries for each command
         if print_all_summary :
-            print ("\nAvailable commands in Glance:")
-
-            # print first line of docstring
-            for cmd in commands:
-                ds = commands[cmd].__doc__.split('\n')[0]
-                print ("\t%-16s %s" % (cmd,ds))
+            print("\n" + _get_all_commands_help_string(commands,))
 
     # all the local public functions are considered part of glance, collect them up
     commands.update(dict(x for x in list(locals().items()) if x[0] not in prior))
@@ -1867,7 +1879,9 @@ def main():
         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()), )
+    options = config_organizer.parse_arguments(get_glance_version_string(),
+                                               list(lower_locals.keys()),
+                                               _get_all_commands_help_string(commands,), )
     args = options.misc
 
     if options.self_test:
diff --git a/pyglance/glance/config_organizer.py b/pyglance/glance/config_organizer.py
index c5b62e6..8847504 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 (version_string, commands_list, ) :
+def parse_arguments (version_string, commands_list, commands_help_text, ) :
     """
     Parse command line options and return an options object
 
@@ -491,7 +491,7 @@ def parse_arguments (version_string, commands_list, ) :
         'Aerosol COD$'
     """
     # set the options available to the user on the command line
-    parser = argparse.ArgumentParser(usage=usage)
+    parser = argparse.ArgumentParser(usage=usage, epilog=commands_help_text, formatter_class=argparse.RawDescriptionHelpFormatter,)
 
     # option to run a test
     parser.add_argument('-t', '--test', dest="self_test",
-- 
GitLab