diff mbox series

[3/3] git-p4: [usability] Show detailed help when parsing options fail

Message ID 2a10890ef76697dbdd67b4c416077726100f88be.1575901009.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series git-p4: Usability enhancements | expand

Commit Message

Johannes Schindelin via GitGitGadget Dec. 9, 2019, 2:16 p.m. UTC
From: Ben Keene <seraphire@gmail.com>

When a user provides invalid parameters to git-p4, the program
reports the failure but does not provide the correct command syntax.

Add an exception handler to the command-line argument parser to display
the command's specific command line parameter syntax when an exception
is thrown. Rethrow the exception so the current behavior is retained.

Signed-off-by: Ben Keene <seraphire@gmail.com>
---
 git-p4.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Junio C Hamano Dec. 9, 2019, 10:24 p.m. UTC | #1
"Ben Keene via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Ben Keene <seraphire@gmail.com>
>
> When a user provides invalid parameters to git-p4, the program
> reports the failure but does not provide the correct command syntax.
>
> Add an exception handler to the command-line argument parser to display
> the command's specific command line parameter syntax when an exception
> is thrown. Rethrow the exception so the current behavior is retained.

Makes sense, I guess.

I forgot to mention this, but from the titles of all three patches I
would probably drop [usability] thing and downcase the first verb,
e.g.

    Subject: [PATCH 3/3] git-p4: show detailed help when parsing options fail

if I were writing these patches.

Thanks.
diff mbox series

Patch

diff --git a/git-p4.py b/git-p4.py
index 856fe82079..cb594baeef 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -4166,7 +4166,12 @@  def main():
                                    description = cmd.description,
                                    formatter = HelpFormatter())
 
-    (cmd, args) = parser.parse_args(sys.argv[2:], cmd);
+    try:
+        (cmd, args) = parser.parse_args(sys.argv[2:], cmd);
+    except:
+        parser.print_help()
+        raise
+
     global verbose
     verbose = cmd.verbose
     if cmd.needsGit: