From 1574e8a3a8982fab9278ad534f9427d464e4bffb Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Fri, 16 Jul 2021 21:43:44 -0700 Subject: Various --- config.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'config.py') diff --git a/config.py b/config.py index dccfc27..81351cf 100644 --- a/config.py +++ b/config.py @@ -69,7 +69,7 @@ import os import pprint import re import sys -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional # This module is commonly used by others in here and should avoid # taking any unnecessary dependencies back on them. @@ -157,7 +157,7 @@ def is_flag_already_in_argv(var: str): return False -def parse(entry_module: str) -> Dict[str, Any]: +def parse(entry_module: Optional[str]) -> Dict[str, Any]: """Main program should call this early in main()""" global config_parse_called if config_parse_called: @@ -166,17 +166,19 @@ def parse(entry_module: str) -> Dict[str, Any]: global saved_messages # If we're about to do the usage message dump, put the main module's - # argument group first in the list, please. + # argument group first in the list (if possible), please. reordered_action_groups = [] prog = sys.argv[0] + for arg in sys.argv: if arg == '--help' or arg == '-h': - print(entry_module) for group in args._action_groups: - if entry_module in group.title or prog in group.title: - reordered_action_groups.insert(0, group) + if entry_module is not None and entry_module in group.title: + reordered_action_groups.insert(0, group) # prepend + elif prog in group.title: + reordered_action_groups.insert(0, group) # prepend else: - reordered_action_groups.append(group) + reordered_action_groups.append(group) # append args._action_groups = reordered_action_groups # Examine the environment variables to settings that match -- cgit v1.3