blob: 33e441550d6d013152e24aa6a43a33fe6e9b570a [file] [log] [blame]
Matthew Maurer32e76692020-06-02 11:15:15 -07001//! A somewhat comprehensive example of a typical `StructOpt` usage.use
David LeGare12ae7f82022-03-02 16:20:50 +00002//!
3//! Running this example with --help prints this message:
4//! -----------------------------------------------------
5//! basic 0.3.25
6//! A basic example
7//!
8//! USAGE:
9//! basic [FLAGS] [OPTIONS] --output <output> [--] [FILE]...
10//!
11//! FLAGS:
12//! -d, --debug Activate debug mode
13//! -h, --help Prints help information
14//! -V, --version Prints version information
15//! -v, --verbose Verbose mode (-v, -vv, -vvv, etc.)
16//!
17//! OPTIONS:
18//! -l, --level <level>... admin_level to consider
19//! -c, --nb-cars <nb-cars> Number of cars
20//! -o, --output <output> Output file
21//! -s, --speed <speed> Set speed [default: 42]
22//!
23//! ARGS:
24//! <FILE>... Files to process
25//! -----------------------------------------------------
Matthew Maurer32e76692020-06-02 11:15:15 -070026
27use std::path::PathBuf;
28use structopt::StructOpt;
29
30/// A basic example
31#[derive(StructOpt, Debug)]
32#[structopt(name = "basic")]
33struct Opt {
34 // A flag, true if used in the command line. Note doc comment will
35 // be used for the help message of the flag. The name of the
36 // argument will be, by default, based on the name of the field.
37 /// Activate debug mode
38 #[structopt(short, long)]
39 debug: bool,
40
41 // The number of occurrences of the `v/verbose` flag
42 /// Verbose mode (-v, -vv, -vvv, etc.)
43 #[structopt(short, long, parse(from_occurrences))]
44 verbose: u8,
45
46 /// Set speed
47 #[structopt(short, long, default_value = "42")]
48 speed: f64,
49
50 /// Output file
51 #[structopt(short, long, parse(from_os_str))]
52 output: PathBuf,
53
54 // the long option will be translated by default to kebab case,
55 // i.e. `--nb-cars`.
56 /// Number of cars
57 #[structopt(short = "c", long)]
58 nb_cars: Option<i32>,
59
60 /// admin_level to consider
61 #[structopt(short, long)]
62 level: Vec<String>,
63
64 /// Files to process
65 #[structopt(name = "FILE", parse(from_os_str))]
66 files: Vec<PathBuf>,
67}
68
69fn main() {
70 let opt = Opt::from_args();
71 println!("{:#?}", opt);
72}