[PATCH v3 2/4] git-p4: show detailed help when parsing options fail
- From
Ben Keene via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Dec 12, 2019, 19:46 UTC
- Message-ID
- <5c5c9816322583e36b59cb0649bb03fb6e06e8a7.1576179987.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.675.v3.git.git.1576179987.gitgitgadget@gmail.com>
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(-)
diff --git a/git-p4.py b/git-p4.py index a05385ee2a..45c0175a68 100755 --- a/git-p4.py +++ b/git-p4.py @@ -4145,7 +4145,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:
-- gitgitgadget