clap/clap_derive/examples/arg_enum.rs
Ed Page 6cc76e7237 fix(derive): Clap should not derive ArgEnum
While having convinience derives can be helpful, deriving traits that
are not used in similar situations (`Clap` and `ArgEnum`) can make
things harder
- From a user, derives are opaque and create uncertainty on how to use
  the API if not kept crystal clear (deriving a name gives you the trait
  by that name)
- This makes documentation harder to write and read
- You can use types in unintended places, which is made worse for crate
  APIs because changing this breaks compatibility.

Fixes #2584
2021-07-14 10:50:26 -05:00

25 lines
452 B
Rust

//! Usage example of `arg_enum`
//!
//! All the variants of the enum and the enum itself support `rename_all`
use clap::{ArgEnum, Clap};
#[derive(ArgEnum, Debug, PartialEq)]
enum ArgChoice {
Foo,
Bar,
// Aliases are supported
#[clap(alias = "b", alias = "z")]
Baz,
}
#[derive(Clap, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum)]
arg: ArgChoice,
}
fn main() {
let opt = Opt::parse();
println!("{:#?}", opt);
}