mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
d840d5650e
Before #2005, `Clap` was a special trait that derived all clap traits it detected were relevant (including an enum getting both `ArgEnum`, `Clap`, and `Subcommand`). Now, we have elevated `Clap`, `Args`, `Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't very descriptive. This also helps further clarify the relationships so a crate providing an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely to choose the needed trait to derive. Also, my proposed fix fo #2785 includes making `App` attributes almost exclusively for `Clap`. Clarifying the names/roles will help communicate this. For prior discussion, see #2583
47 lines
790 B
Rust
47 lines
790 B
Rust
//! How to use `#[clap(skip)]`
|
|
|
|
use clap::Parser;
|
|
|
|
#[derive(Parser, Debug, PartialEq)]
|
|
pub struct Opt {
|
|
#[clap(long, short)]
|
|
number: u32,
|
|
#[clap(skip)]
|
|
k: Kind,
|
|
#[clap(skip)]
|
|
v: Vec<u32>,
|
|
|
|
#[clap(skip = Kind::A)]
|
|
k2: Kind,
|
|
#[clap(skip = vec![1, 2, 3])]
|
|
v2: Vec<u32>,
|
|
#[clap(skip = "cake")] // &str implements Into<String>
|
|
s: String,
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
enum Kind {
|
|
A,
|
|
B,
|
|
}
|
|
|
|
impl Default for Kind {
|
|
fn default() -> Self {
|
|
Kind::B
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
assert_eq!(
|
|
Opt::parse_from(&["test", "-n", "10"]),
|
|
Opt {
|
|
number: 10,
|
|
k: Kind::B,
|
|
v: vec![],
|
|
|
|
k2: Kind::A,
|
|
v2: vec![1, 2, 3],
|
|
s: String::from("cake")
|
|
}
|
|
);
|
|
}
|