Hacker News new | ask | show | jobs
by moses-palmer 906 days ago
Yeah, I was hoping the `clap` macros would perform some unthinkable magic there... I will have to update the help with a listing.

In the mean time, have a look here[1] for the possible values.

[1]: https://github.com/moses-palmer/labyru/blob/7b92be3ae279a9ff...

1 comments

`clap` does have magic for enums:

  use clap::{Parser, ValueEnum};

  #[derive(ValueEnum, Debug, Clone)]
  pub enum Foo {
    Bar,
    Baz,
  }

  #[derive(Parser, Debug)]
  #[command(author, version, about, long_about = None)]
  pub struct Args {
    /// description
    #[arg(short = 'f', long = "foo", value_enum, default_value = "bar")]
    foo: Foo,
  }
The output of `--help` will look like:

  -f, --foo <FOO>  description [default: bar] [possible values: bar, baz]
This is with clap >= 4.4 with the derive feature.