/ clap Public
External subcommands that alias built-in subccommands cause panics #3263
Area: #[derive]` macro API
Area: documentation, including docs.rs, readme, examples, etc...
Area: Parser's logic and needs it changed somehow.
Category: Updating dependencies
Call for participation: Experience needed to fix: Medium / intermediate
Meta: Implementing or merging this will introduce a breaking change.
Please complete the following tasks
rustc 1.57.0 (f1edd0429 2021-11-29)
Minimal reproducible code
Steps to reproduce the bug with the above code
This happens because
--is escaping the command so it becomes an external subcommand that aliases the built-in. A simple
matchdoes not catch this and we then try to access
ArgMatchesmeant for external subcommands (only
Its a bit unclear.
cargojust passes the
ArgMatchesalong, warning about the contents, like:
So with the above problem, that'd look like:
Ran into this when porting cargo to clap3 with a test failure from
cargotakes the approach of running the escaped command but ignoring the arguments. This means we pass an external subcommand's
ArgMatchesinto a function assuming its getting
ArgMatchesand panics when it accesses an "undefined" field.
Builder users can detect that its an external subcommand by checking for
values_of("")but derive users can't do that.
You have to even know to do that.
Once you do that, the question is what is next. Pass it through? Error? Fallback to the built-in like cargo? Seems like this should be the users choice. The challenge is with the fallback. They now need an
ArgMatchesthat has the same shape (ie won't panic) when passing to that part of their program.
The text was updated successfully, but these errors were encountered: