From a34a9fed116d24562fbe4bb8d456ade85f056c36 Mon Sep 17 00:00:00 2001 From: rffontenelle Date: Tue, 18 Jul 2023 12:13:18 +0000 Subject: [PATCH] Improve parse_args (#2) This solves two minor issues of the `powrap --help` output: - First one is that argparse shows short and then long form of --help option, while powrap's arguments show long and then short, causing it to look like: ``` options: -h, --help show this help message and exit --modified, -m Use git to find modified files ... -C GIT_ROOT To use with --modified to tell ... --quiet, -q Do not show progress bar ... ... ``` - The other thing is that the exit code is set in multi-line string, but not actually printed as multi-line string. While it looks compacted and OK in the printed help message, I assume that's not the intended so I set RawTextHelpFormatter to make sure the formatting is honored. ``` exit code: 0:nothing to do 1:would rewrap 127:error running msgcat ``` Reviewed-on: https://git.afpy.org/AFPy/powrap/pulls/2 Co-authored-by: rffontenelle Co-committed-by: rffontenelle --- powrap/powrap.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/powrap/powrap.py b/powrap/powrap.py index 579acbc..81e60bd 100644 --- a/powrap/powrap.py +++ b/powrap/powrap.py @@ -94,14 +94,15 @@ def parse_args(): parser = argparse.ArgumentParser( prog="powrap", description="Ensure po files are using the standard gettext format", + formatter_class=argparse.RawTextHelpFormatter, epilog="""exit code: 0:nothing to do 1:would rewrap 127:error running msgcat""", ) parser.add_argument( - "--modified", "-m", + "--modified", action="store_true", help="Use git to find modified files instead of passing them as arguments.", ) @@ -114,11 +115,11 @@ def parse_args(): default=Path.cwd(), ) parser.add_argument( - "--quiet", "-q", action="store_true", help="Do not show progress bar." + "-q", "--quiet", action="store_true", help="Do not show progress bar." ) parser.add_argument( - "--diff", "-d", + "--diff", action="store_true", help="Don't write the files back, just output a diff for each file on stdout " "(implies --check).",