2020-04-22 10:57:21 +00:00
|
|
|
//! Usage example of `arg_enum`
|
|
|
|
//!
|
|
|
|
//! All the variants of the enum and the enum itself support `rename_all`
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
use clap::{ArgEnum, Parser};
|
2020-04-22 07:25:41 +00:00
|
|
|
|
2021-09-29 16:05:19 +00:00
|
|
|
#[derive(ArgEnum, Debug, PartialEq, Clone)]
|
2020-04-22 07:25:41 +00:00
|
|
|
enum ArgChoice {
|
2021-09-18 12:13:44 +00:00
|
|
|
/// Descriptions are supported as doc-comment
|
2020-04-22 07:25:41 +00:00
|
|
|
Foo,
|
2021-09-18 12:13:44 +00:00
|
|
|
// Renames are supported
|
|
|
|
#[clap(name = "b-a-r")]
|
2020-04-22 07:25:41 +00:00
|
|
|
Bar,
|
2020-04-22 10:57:21 +00:00
|
|
|
// Aliases are supported
|
|
|
|
#[clap(alias = "b", alias = "z")]
|
2020-04-22 07:25:41 +00:00
|
|
|
Baz,
|
2021-09-18 12:13:44 +00:00
|
|
|
// Hiding variants from help and completion is supported
|
2021-09-26 23:29:10 +00:00
|
|
|
#[clap(hidden = true)]
|
2021-09-18 12:13:44 +00:00
|
|
|
Hidden,
|
2020-04-22 07:25:41 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2020-04-22 07:25:41 +00:00
|
|
|
struct Opt {
|
|
|
|
#[clap(arg_enum)]
|
|
|
|
arg: ArgChoice,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let opt = Opt::parse();
|
|
|
|
println!("{:#?}", opt);
|
|
|
|
}
|