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

[docs] No mention how to skip enum variants on the ValueEnum derive macro #4327

Closed
2 tasks done
dnaka91 opened this issue Oct 1, 2022 · 0 comments · Fixed by #4328
Closed
2 tasks done

[docs] No mention how to skip enum variants on the ValueEnum derive macro #4327

dnaka91 opened this issue Oct 1, 2022 · 0 comments · Fixed by #4328
Labels
C-enhancement Category: Raise on the bar on expectations

Comments

@dnaka91
Copy link
Contributor

dnaka91 commented Oct 1, 2022

Please complete the following tasks

Clap Version

4.0.7

Describe your use case

I was looking for a way to skip a variant from an enum, when using the ValueEnum derive macro. Turns out there actually IS a way, but it's not mentioned anywhere in the reference in a direct way.

Simple example:

#[derive(Debug, ValueEnum)]
struct Format {
    Text,
    Json,
    #[value(skip)]
    None, // handled by another flag manually
}

The hide attribute is mentioned (somewhat), as one can check the available functions on the PossibleValue struct, but it's not the same as it only hides it in the docs. Only with #[value(skip)] it's fully omitted and becomes an impossible value to create through the CLI.

The skip attribute is only mentioned in a few places in the derive reference:

Describe the solution you'd like

There is already a ValueEnum section for attributes in the docs: https://docs.rs/clap/4.0.7/clap/_derive/index.html#valueenum-attributes

This one only needs an additional entry for the skip attribute, describing that it can be used to omit variants from the generated implementation.

Alternatives, if applicable

No response

Additional Context

No response

@dnaka91 dnaka91 added the C-enhancement Category: Raise on the bar on expectations label Oct 1, 2022
epage pushed a commit that referenced this issue Oct 5, 2022
Documenting the `skip` attribute for the `ValueEnum` derive macro promptly, as it's not mentioned anywhere else.

Fixes #4327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant