mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 00:27:13 +00:00
6cc76e7237
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
25 lines
452 B
Rust
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);
|
|
}
|