mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
392effe319
This PR switches the Arg::Short macro to take a character instead of a string. It removes the hacky code in the Method to_token method and implements the logic for Short when parsing the clap derive arguments. Fixes #1815.
48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
//! A somewhat comprehensive example of a typical `StructOpt` usage.use
|
|
|
|
use clap::Clap;
|
|
use std::path::PathBuf;
|
|
|
|
/// A basic example
|
|
#[derive(Clap, Debug)]
|
|
#[clap(name = "basic")]
|
|
struct Opt {
|
|
// A flag, true if used in the command line. Note doc comment will
|
|
// be used for the help message of the flag. The name of the
|
|
// argument will be, by default, based on the name of the field.
|
|
/// Activate debug mode
|
|
#[clap(short, long)]
|
|
debug: bool,
|
|
|
|
// The number of occurrences of the `v/verbose` flag
|
|
/// Verbose mode (-v, -vv, -vvv, etc.)
|
|
#[clap(short, long, parse(from_occurrences))]
|
|
verbose: u8,
|
|
|
|
/// Set speed
|
|
#[clap(short, long, default_value = "42")]
|
|
speed: f64,
|
|
|
|
/// Output file
|
|
#[clap(short, long, parse(from_os_str))]
|
|
output: PathBuf,
|
|
|
|
// the long option will be translated by default to kebab case,
|
|
// i.e. `--nb-cars`.
|
|
/// Number of cars
|
|
#[clap(short = 'c', long)]
|
|
nb_cars: Option<i32>,
|
|
|
|
/// admin_level to consider
|
|
#[clap(short, long)]
|
|
level: Vec<String>,
|
|
|
|
/// Files to process
|
|
#[clap(name = "FILE", parse(from_os_str))]
|
|
files: Vec<PathBuf>,
|
|
}
|
|
|
|
fn main() {
|
|
let opt = Opt::parse();
|
|
println!("{:#?}", opt);
|
|
}
|