-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
Clap Version
4.1.4
Describe your use case
Clap has a good fix suggestion mechanism when a user types something wrong. It seems to be based on Jaro distance.
A developer sometimes wants to provide an additional context on a specific situation to users. In order to do so, clap needs to support things like “when a user passes a non-existent flag/command/value/whatever, suggest a flag with this custom message instead.”
Describe the solution you'd like
There are lots of different ways and layers to support this feature.
I'll try to dump only one silly idea here: Clap seems to have several kinds of suggested fix. I don't have any knowledge of clap internals, but feel like at least Arg
and Command
can have a method, say suggests
, accepting a flag name and an alternate message, such as
Arg::new("directory")
.help("Change to DIRECTORY before doing anything")
.short('C')
.value_name("DIRECTORY")
+ .suggests("--cwd", "long flag --cwd is not yet supported. Please use `-C` instead")
Not a good idea but you've got the gist.
Alternatives, if applicable
Do it manually on application-side. Like
- https://github.com/rust-lang/cargo/blob/39c13e67a5962466cc7253d41bc1099bbcb224c3/src/bin/cargo/commands/tree.rs#L230-L235
- https://github.com/rust-lang/cargo/blob/39c13e67a5962466cc7253d41bc1099bbcb224c3/src/bin/cargo/commands/read_manifest.rs#L4-L13
They are not really in the same situation of this feature requests, as Cargo keeps a stable flag way longer than usual. However, if Cargo decide to remove those subcommand/flags, it may utilize this feature to provide good suggestions.
Additional Context
This idea was originally from rust-lang/cargo#11702