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.
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:
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