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 Docstrings of variants in ArgEnum in --help #3784

Closed
2 tasks done
nipunn1313 opened this issue Jun 2, 2022 · 4 comments
Closed
2 tasks done

Show Docstrings of variants in ArgEnum in --help #3784

nipunn1313 opened this issue Jun 2, 2022 · 4 comments
Labels
C-enhancement Category: Raise on the bar on expectations

Comments

@nipunn1313
Copy link

Please complete the following tasks

Clap Version

3.1.14

Describe your use case

Would like something like this:

#[derive(Parser, Debug)]
struct Args {
    /// Choice of variant
    #[clap(long, arg_enum)]
    v: Variants
}

#[derive(ArgEnum, Clone, Copy, Debug)]
pub enum Variants {
    /// Variant 1
    V1,
    /// Variant 2
    V2,
    /// Variant 3
    V3,
}

fn main() {
  let args = Args::parse();
}

Describe the solution you'd like

I would ideally like --help to show the description of the variants (V1, V2, V3).
Currently, it just shows the docstring for v: Variants

Alternatives, if applicable

Could also work to have this be gated behind a derive arg attribute on the struct

Additional Context

No response

@nipunn1313 nipunn1313 added the C-enhancement Category: Raise on the bar on expectations label Jun 2, 2022
@epage
Copy link
Member

epage commented Jun 3, 2022

I believe this is a duplicate of #3312 which was implemented in #3503 which was released in 3.1.4.

It is gated behind unstable-v4 as we were uncomfortable with taking a doc string we previously ignored and starting to put it in the help.

@epage epage closed this as completed Jun 3, 2022
@nipunn1313
Copy link
Author

thanks! Appreciate the team behind clap

@hulxv
Copy link

hulxv commented Jun 4, 2022

I believe this is a duplicate of #3312 which was implemented in #3503 which was released in 3.1.4.

It is gated behind unstable-v4 as we were uncomfortable with taking a doc string we previously ignored and starting to put it in the help.

Is it possible to do it by derive way like that's example

#[derive(Parser, Debug)]
struct Args {
    /// Choice of variant
    #[clap(long, arg_enum)]
    v: Variants
}

#[derive(ArgEnum, Clone, Copy, Debug)]
pub enum Variants {
    /// Variant 1
    V1,
    /// Variant 2
    V2,
    /// Variant 3
    V3,
}

fn main() {
  let args = Args::parse();
}

or that's available for builder only now?

@epage
Copy link
Member

epage commented Jun 4, 2022

Yes, the derive will automatically pick up doc comments. While the PR didn't explicitly add any code for that, it picked it up through shared code. I'm adding an explicit test for it.

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

No branches or pull requests

3 participants