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

Show possible values when an arguments value is missing #3320

Closed
2 tasks done
epage opened this issue Jan 19, 2022 · 2 comments · Fixed by #3394
Closed
2 tasks done

Show possible values when an arguments value is missing #3320

epage opened this issue Jan 19, 2022 · 2 comments · Fixed by #3394
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate

Comments

@epage
Copy link
Member

epage commented Jan 19, 2022

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Clap Version

v3.0.6

Describe your use case

Many CLIs allow using the argument without a value to list what values are available. This allows a more targeted browsing than digging in --help

Today, clap just points people to help

$ git-stack --color
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/src/personal/git-stack/target/debug/git-stack --color`
error: The argument '--color <WHEN>' requires a value but none was supplied

USAGE:
    git-stack [OPTIONS]

For more information try --help

Describe the solution you'd like

For example:

$ cargo test --test    
error: "--test" takes one argument.                                      
Available tests:                    
    builder     
    derive                                                               
    derive_ui                       
    examples                                                             
    macros                                                                                                                                         
    yaml                                                                 

(granted, this is dynamically generating the list)

We could also list the PossibleValue::help like in #3312.

Alternatives, if applicable

No response

Additional Context

No response

@epage epage added C-enhancement Category: Raise on the bar on expectations A-help Area: documentation, including docs.rs, readme, examples, etc... E-medium Call for participation: Experience needed to fix: Medium / intermediate labels Jan 19, 2022
@epage
Copy link
Member Author

epage commented Jan 19, 2022

Maybe we should also have the unknown value error point people to this

Today:

$ git-stack --color lklk
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/src/personal/git-stack/target/debug/git-stack --color lklk`
error: Invalid value for '--color <WHEN>': Unknown color choice 'lklk'

For more information try --help

$ git-stack --color
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/src/personal/git-stack/target/debug/git-stack --color`
error: The argument '--color <WHEN>' requires a value but none was supplied

USAGE:
    git-stack [OPTIONS]

For more information try --help

Potential future:

$ git-stack --color lklk
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/src/personal/git-stack/target/debug/git-stack --color lklk`
error: Invalid value for '--color <WHEN>': Unknown color choice 'lklk'

For valid color choices try `git-stack --color`
For more information try `git-stack --help`

$ git-stack --color
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/src/personal/git-stack/target/debug/git-stack --color`
error: The argument '--color <WHEN>' requires a value but none was supplied

Possible values:
- auto
- always
- never
- 
For more information try `git-stack --help`

@epage
Copy link
Member Author

epage commented Jan 19, 2022

Correction: looks like I wasn't using possible_values. The error is actually

$ cargo run -- --color foo
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `/home/epage/src/personal/concolor/target/debug/concolor-example --color foo`
error: "foo" isn't a valid value for '--color <WHEN>'
        [possible values: always, auto, never]

USAGE:
    concolor-example --color <WHEN>

For more information try --help

epage added a commit to epage/clap that referenced this issue Feb 2, 2022
This is inspired by cargo which allows you to run `cargo test --test`
and it will list the possible tests (obviously we can't support that atm
because that requires a lot of runtime processing).  When we do have a
static list of possible values, we can at least show those.

Fixes clap-rs#3320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant