Skip to content

Support custom suggested fix messages for specific flags #4706

@weihanglo

Description

@weihanglo

Please complete the following tasks

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-helpArea: documentation, including docs.rs, readme, examples, etc...C-enhancementCategory: Raise on the bar on expectationsS-waiting-on-designStatus: Waiting on user-facing design to be resolved before implementing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions