[v2,2/4] git-p4: show detailed help when parsing options fail
diff mbox series

Message ID 1d4f4e210b480b6267207044b1bf79a59a70de24.1575991374.git.gitgitgadget@gmail.com
State New
Headers show
Series
  • git-p4: Usability enhancements
Related show

Commit Message

Philippe Blain via GitGitGadget Dec. 10, 2019, 3:22 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(-)

Patch
diff mbox series

diff --git a/git-p4.py b/git-p4.py
index 0fa562fac9..daa6e8a57a 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -4151,7 +4151,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: