diff options
| author | Scott Gasch <[email protected]> | 2022-02-03 15:44:32 -0800 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-02-03 15:44:32 -0800 |
| commit | 01f7083eeef0330820e0e5d03fb83a3a8bfd2777 (patch) | |
| tree | daac94d4ce9f7bda40a07a009760c19d54d00e23 /config.py | |
| parent | 65983ec2e03c97ca44e6374b226f796413bdc637 (diff) | |
Add a formatter that handles raw help text, optionally.
Diffstat (limited to 'config.py')
| -rw-r--r-- | config.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -84,10 +84,24 @@ 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) + + # A global parser that we will collect arguments into. args = argparse.ArgumentParser( description=None, - formatter_class=argparse.ArgumentDefaultsHelpFormatter, + formatter_class=OptionalRawFormatter, fromfile_prefix_chars="@", epilog=f'{program_name} uses config.py ({__file__}) for global, cross-module configuration setup and parsing.', ) |
