argparse: Accept the progname in the command path #9160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
The documentation of
cmd_path()
states that it always starts with the progname. Indeed,argparse:parse/{1,2}
returns a command path with the progname at the beginning.However, if
argparse:help/2
is called with#{command => CmdPath}
in the parser options withCmdPath
starting with the progname, it crashes with abadkey
exception because it expects the command path to only contain commands and sub-commands.How
The patch drops the first element of the command path if it matches the progname.
This adds support for the correct values of
CmdPath
while retaining backward compatibility with callers that dropped the progname themselves to work around the issue.