Users can accidentally design broken CLIs when combining subcommands with unbounded positional arguments #3721
Labels
A-builder
Area: Builder API
C-bug
Category: Updating dependencies
E-easy
Call for participation: Experience needed to fix: Easy / not much
M-breaking-change
Meta: Implementing or merging this will introduce a breaking change.
Maintainer's notes: Below is the original issue that came from misusing clap's API. We could add a debug assert to help guide users to use the API correctly.
Please complete the following tasks
Rust Version
rustc 1.60.0 (7737e0b5c 2022-04-04)
Clap Version
3.1.17
Minimal reproducible code
Steps to reproduce the bug with the above code
$ cargo run -- -h
Actual Behaviour
Expected Behaviour
OR (perhaps it's up to taste)
If subcommand is required then global arguments should only go after the subcommand is named.
Additional Context
$ cargo run -- help search
matches the expected behavior just fineI also tried adding
args_conflicts_with_subcommands=true
toCli
, but it still doesn't produce expected behavior. It results in:which seems wrong because the first usage case doesn't require a subcommand
I could add the
files
argument to bothFilter
andSearch
structs, but this seems messy, and prevents me from having access to the shared argument before matching over the subcommands.Debug Output
No response
The text was updated successfully, but these errors were encountered: