+ # If we're about to do the usage message dump, put the main module's
+ # argument group last in the list (if possible) so that when the user
+ # passes -h or --help, it will be visible on the screen w/o scrolling.
+ reordered_action_groups = []
+ global prog
+ for arg in sys.argv:
+ if arg == '--help' or arg == '-h':
+ for group in args._action_groups:
+ if entry_module is not None and entry_module in group.title:
+ reordered_action_groups.append(group)
+ elif program_name in group.title:
+ reordered_action_groups.append(group)
+ else:
+ reordered_action_groups.insert(0, group)
+ args._action_groups = reordered_action_groups
+
+ # Examine the environment variables that match known flags. For a
+ # flag called --example_flag the corresponding environment
+ # variable would be called EXAMPLE_FLAG.