X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=config.py;h=1ac5cff30add3fcbd0eb0a03d7361f06515cbbfe;hb=e8fbbb7306430478dec55d2c963eed116d8330cc;hp=42a7044d21c6d86c0f4a793b81d7a70ed23b04e9;hpb=713a609bd19d491de03debf8a4a6ddf2540b13dc;p=python_utils.git diff --git a/config.py b/config.py index 42a7044..1ac5cff 100644 --- a/config.py +++ b/config.py @@ -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.', ) @@ -145,6 +159,10 @@ group.add_argument( ) +def overwrite_argparse_epilog(msg: str) -> None: + args.epilog = msg + + def is_flag_already_in_argv(var: str): """Is a particular flag passed on the commandline?""" for _ in sys.argv: