Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse: Accept the progname in the command path #9159

Conversation

dumbbell
Copy link
Contributor

@dumbbell dumbbell commented Dec 9, 2024

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 with CmdPath starting with the progname, it crashes with a badkey 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.

[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 with `CmdPath` starting with the progname, it crashes
with a `badkey` 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.
@dumbbell
Copy link
Contributor Author

dumbbell commented Dec 9, 2024

Oops, I submitted it against the wrong branch… Closing and resubmitting!

New pull request: #9160.

@dumbbell dumbbell closed this Dec 9, 2024
@dumbbell dumbbell deleted the argparse-fix-command-parser-option-handling-in-format_help branch December 14, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant