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

Support about for possible_values e.g. ArgEnum #2731

Closed
ModProg opened this issue Aug 21, 2021 · 3 comments · Fixed by #2758 or #2762
Closed

Support about for possible_values e.g. ArgEnum #2731

ModProg opened this issue Aug 21, 2021 · 3 comments · Fixed by #2758 or #2762

Comments

@ModProg
Copy link
Contributor

ModProg commented Aug 21, 2021

Clap Version

master

Describe your use case

Sometimes the value itself my not give enough information to the user, therefore it would be helpful to be able to show and additional about in e.g. fish completions.
Fish does that for example for __fish_complete_users:
grafik

Describe the solution you'd like

Support adding abouts/documentation for the possible completion values.

For ArgEnum:

#[derive(Clone, Copy, ArgEnum)]
pub enum ShellType {
    /// the default Shell
    Bash,
    /// the friendly interactive Shell
    Fish
}

This should result in the following completions in fish for example:
grafik

Additional Context

For fish this is somewhat related to #2730

@ModProg ModProg changed the title Support abbout for possible_values e.g. ArgEnum Support about for possible_values e.g. ArgEnum Aug 21, 2021
@epage
Copy link
Member

epage commented Aug 21, 2021

The challenge is the derive API is built on top of the builder API, so we need to come up with a way to specify this within the builder API.

Possibly a variant of possible_values that takes a slice of tuples.

@ModProg
Copy link
Contributor Author

ModProg commented Aug 21, 2021

Possibly a variant of possible_values that takes a slice of tuples.

Tho this is not very builder like :D but as that is probably the only information you would want to attach to a possible_value it makes sense.

I could also imagine somthing more like this (somewhat verbose if there can only be about:

.possible_value(PVal::new("bash").about("the default Shell"))
.possible_value(PVal::new("fish").about("the friendly interactive Shell"))
.possible_value(PVal::new("sh"))

Another option would be to do it via possible_value and possible_value_about:

.possible_value_about("bash","the default Shell")
.possible_value_about("fish","the friendly interactive Shell")
.possible_value("sh")

When using possible_values_about:

.possible_values_about(
    &[
        ("bash", "the default Shell"), 
        ("fish", "the friendly interactive Shell"),
        ("sh", "")
    ]
)
// or
.possible_values_about(
    &[
        ("bash", "the default Shell"), 
        ("fish", "the friendly interactive Shell")
    ]
)
.possible_value("sh")

Internally this would need to be stored in a Vec of Tuples.

@ModProg
Copy link
Contributor Author

ModProg commented Aug 21, 2021

I drafted an Implementation in #2733 using the .possible_values_about. It works for zsh and fish, because those currently implement possible_args completion.

This was referenced Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants