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 #9160

Open
wants to merge 1 commit into
base: maint
Choose a base branch
from

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.
Copy link
Contributor

github-actions bot commented Dec 9, 2024

CT Test Results

    2 files     95 suites   1h 7m 53s ⏱️
2 158 tests 2 109 ✅ 48 💤 1 ❌
2 517 runs  2 466 ✅ 50 💤 1 ❌

For more details on these failures, see this check.

Results for commit 04d4c92.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

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