2020-10-08 22:05:05 +00:00
|
|
|
//! A somewhat comprehensive example of a typical `clap_derive` usage.
|
2017-02-03 00:03:51 +00:00
|
|
|
|
2020-10-08 22:05:05 +00:00
|
|
|
use clap::{Clap, ValueHint};
|
2018-02-01 23:00:08 +00:00
|
|
|
use std::path::PathBuf;
|
2017-02-03 00:03:51 +00:00
|
|
|
|
2017-06-15 13:18:17 +00:00
|
|
|
/// A basic example
|
2018-07-02 18:45:17 +00:00
|
|
|
#[derive(Clap, Debug)]
|
|
|
|
#[clap(name = "basic")]
|
2017-02-03 00:03:51 +00:00
|
|
|
struct Opt {
|
2018-02-01 23:00:08 +00:00
|
|
|
// A flag, true if used in the command line. Note doc comment will
|
2020-01-07 10:17:23 +00:00
|
|
|
// 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.
|
2017-06-15 13:18:17 +00:00
|
|
|
/// Activate debug mode
|
2020-01-07 10:17:23 +00:00
|
|
|
#[clap(short, long)]
|
2017-02-04 00:43:44 +00:00
|
|
|
debug: bool,
|
2017-06-15 13:18:17 +00:00
|
|
|
|
2020-01-07 10:17:23 +00:00
|
|
|
// The number of occurrences of the `v/verbose` flag
|
2018-02-03 14:15:03 +00:00
|
|
|
/// Verbose mode (-v, -vv, -vvv, etc.)
|
2020-01-07 10:17:23 +00:00
|
|
|
#[clap(short, long, parse(from_occurrences))]
|
2018-02-01 23:00:08 +00:00
|
|
|
verbose: u8,
|
2017-06-15 13:18:17 +00:00
|
|
|
|
|
|
|
/// Set speed
|
2020-01-07 10:17:23 +00:00
|
|
|
#[clap(short, long, default_value = "42")]
|
2017-02-06 22:55:46 +00:00
|
|
|
speed: f64,
|
2017-06-15 13:18:17 +00:00
|
|
|
|
|
|
|
/// Output file
|
2020-10-08 22:05:05 +00:00
|
|
|
#[clap(short, long, parse(from_os_str), value_hint = ValueHint::FilePath)]
|
2018-02-01 23:00:08 +00:00
|
|
|
output: PathBuf,
|
2017-06-15 13:18:17 +00:00
|
|
|
|
2020-01-07 10:17:23 +00:00
|
|
|
// the long option will be translated by default to kebab case,
|
|
|
|
// i.e. `--nb-cars`.
|
2018-02-10 19:57:33 +00:00
|
|
|
/// Number of cars
|
2020-06-17 00:43:31 +00:00
|
|
|
#[clap(short = 'c', long)]
|
2018-02-10 19:57:33 +00:00
|
|
|
nb_cars: Option<i32>,
|
2017-06-15 13:18:17 +00:00
|
|
|
|
|
|
|
/// admin_level to consider
|
2020-01-07 10:17:23 +00:00
|
|
|
#[clap(short, long)]
|
2017-02-04 00:43:44 +00:00
|
|
|
level: Vec<String>,
|
2017-06-15 13:18:17 +00:00
|
|
|
|
|
|
|
/// Files to process
|
2020-10-08 22:05:05 +00:00
|
|
|
#[clap(name = "FILE", parse(from_os_str), value_hint = ValueHint::AnyPath)]
|
2018-02-01 23:00:08 +00:00
|
|
|
files: Vec<PathBuf>,
|
2017-02-03 00:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-07-02 18:45:17 +00:00
|
|
|
let opt = Opt::parse();
|
2020-01-07 10:17:23 +00:00
|
|
|
println!("{:#?}", opt);
|
2017-02-03 00:03:51 +00:00
|
|
|
}
|