-from typing import Any, Dict, List
-
-# Note: at this point in time, logging hasn't been configured and
-# anything we log will come out the root logger.
-
-
-class LoadFromFile(argparse.Action):
- """Helper to load a config file into argparse."""
- def __call__ (self, parser, namespace, values, option_string = None):
- with values as f:
- buf = f.read()
- argv = []
- for line in buf.split(','):
- line = line.strip()
- line = line.strip('{')
- line = line.strip('}')
- m = re.match(r"^'([a-zA-Z_\-]+)'\s*:\s*(.*)$", line)
- if m:
- key = m.group(1)
- value = m.group(2)
- value = value.strip("'")
- if value not in ('None', 'True', 'False'):
- argv.append(f'--{key}')
- argv.append(value)
- parser.parse_args(argv, namespace)
+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.
+
+# Defer logging messages until later when logging has been initialized.
+saved_messages: List[str] = []
+
+# Make a copy of the original program arguments.
+program_name: str = os.path.basename(sys.argv[0])
+original_argv: List[str] = [arg for arg in sys.argv]
+
+
+class OptionalRawFormatter(argparse.HelpFormatter):
+ """This formatter has the same bahavior as the normal argparse text
+ formatter except when the help text of an argument begins with
+ "RAW|". In that case, the line breaks are preserved and the text
+ is not wrapped.
+
+ """
+
+ def _split_lines(self, text, width):
+ if text.startswith('RAW|'):
+ return text[4:].splitlines()
+ return argparse.HelpFormatter._split_lines(self, text, width)