Struct CommandLineParser

Source
pub struct CommandLineParser<'a> { /* private fields */ }
Expand description

The base command line parser.

§Example

use blarg::{CommandLineParser};

let parser = CommandLineParser::new("program")
    // Configure with CommandLineParser::add and CommandLineParser::branch.
    .build();
parser.parse_tokens(empty::slice()).unwrap();

Implementations§

Source§

impl<'a> CommandLineParser<'a>

Source

pub fn new(program: impl Into<String>) -> CommandLineParser<'a>

Create a command line parser.

§Example
use blarg::CommandLineParser;

let parser = CommandLineParser::new("program")
    .build();

parser.parse_tokens(vec![].as_slice()).unwrap();
Examples found in repository?
examples/empty.rs (line 4)
3fn main() {
4    let ap = CommandLineParser::new("empty");
5    let parser = ap.build();
6    parser.parse();
7    println!("empty parser");
8}
More examples
Hide additional examples
examples/demo_summer_b.rs (line 6)
3fn main() {
4    let mut items: Vec<u32> = Vec::default();
5
6    let clp = CommandLineParser::new("summer");
7    let parser = clp
8        .add(
9            Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
10                .help("The items to sum."),
11        )
12        .build();
13
14    parser.parse();
15    let sum: u32 = items.iter().sum();
16    println!("Sum: {sum}");
17}
examples/example.rs (line 5)
2fn main() {
3    let mut verbose: bool = false;
4    let mut value: u32 = 0;
5    let ap = CommandLineParser::new("example");
6    let parser = ap
7        .add(Parameter::option(
8            Switch::new(&mut verbose, true),
9            "verbose",
10            Some('v'),
11        ))
12        .add(Parameter::argument(Scalar::new(&mut value), "value").meta(vec!["type: u32"]))
13        .build();
14    parser.parse();
15    println!("value: {value}, verbose: {verbose}");
16}
examples/demo_organization.rs (line 33)
30fn parse_tokens(parse_fn: impl FnOnce(GeneralParser) -> Result<(), i32>) -> Params {
31    let mut params = Params::init();
32
33    let clp = CommandLineParser::new("organization");
34    let parser = clp
35        .add(Parameter::option(
36            Switch::new(&mut params.verbose, true),
37            "verbose",
38            Some('v'),
39        ))
40        .add(Parameter::argument(
41            Collection::new(&mut params.items, Nargs::AtLeastOne),
42            "item",
43        ))
44        .build();
45
46    // The parse_fn signature is a `Result`.
47    // However, since `GeneralParser::parse` does not return an error (it uses `std::process::exit` under the hood), the `Err` case is only reached via test.
48    parse_fn(parser).expect("test-reachable-only");
49    params
50}
examples/reducer.rs (line 60)
53fn main() {
54    let mut _verbose: bool = false;
55    let mut operand: Operand = Operand::Add;
56    let mut initial: Option<u32> = None;
57    let mut _countries: HashSet<Country> = HashSet::default();
58    let mut items: Vec<u32> = Vec::default();
59
60    let ap = CommandLineParser::new("reducer");
61    let parser = ap
62        .add(
63            Parameter::option(Switch::new(&mut _verbose, true), "verbose", Some('v'))
64                .help("Do dee doo.  We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!"),
65        )
66        .add(
67            Parameter::option(Scalar::new(&mut operand), "operand", Some('o'))
68                .help("moot")
69                .choice(Operand::Add, "+")
70                .choice(Operand::Multiply, "*"),
71        )
72        .add(Parameter::option(Optional::new(&mut initial), "initial", None)
73            .meta(vec!["testing a really long meta.. abcdefghijklmnopqrstuvwxyz"])
74        )
75        .add(Parameter::option(Collection::new(&mut _countries, Nargs::AtLeastOne), "country", None))
76        .add(
77            Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
78                .help("The items."),
79        )
80        .build();
81    parser.parse();
82    println!("Items: {items:?}");
83    execute(_verbose, operand, initial, _countries, items);
84}
examples/foo_bar.rs (line 61)
54fn main() {
55    let mut verbose: bool = false;
56    let mut foo_bar = FooBar::Foo;
57    let mut initial: Option<u32> = None;
58    let mut countries: HashSet<Country> = HashSet::default();
59    let mut items: Vec<u32> = Vec::default();
60
61    let ap = CommandLineParser::new("foo_bar");
62    let parser = ap
63        .add(
64            Parameter::option(Switch::new(&mut verbose, true), "verbose", Some('v'))
65                .help("Do dee doo."),
66        )
67        .branch(
68            Condition::new(Scalar::new(&mut foo_bar), "foo_bar")
69                .choice(FooBar::Foo, "123 abc let's make this one medium long.")
70                .choice(FooBar::Bar, "456 def let's make this one multiple sentences.  We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!")
71                .help("foo'y bar'y stuff")
72                .meta(vec!["a", "b", "c"]),
73        )
74        .command(FooBar::Foo, |sub| {
75            sub.add(Parameter::option(
76                Optional::new(&mut initial),
77                "initial",
78                None,
79            ))
80            .add(
81                Parameter::argument(Collection::new(&mut items, Nargs::Any), "item")
82                    .help("The items."),
83            )
84        })
85        .command(FooBar::Bar, |sub| {
86            sub.add(Parameter::option(
87                Collection::new(&mut countries, Nargs::AtLeastOne),
88                "country",
89                None,
90            ))
91        })
92        .build();
93    parser.parse();
94    println!("Items: {items:?}");
95    execute(verbose, foo_bar, initial, countries, items);
96}
Source

pub fn about(self, description: impl Into<String>) -> CommandLineParser<'a>

Document the about message for this command line parser. If repeated, only the final help message will apply.

An about message documents the command line parser in full sentence/paragraph format. We recommend allowing blarg to format this field (ex: it is not recommended to use line breaks '\n').

§Example
use blarg::CommandLineParser;

let parser = CommandLineParser::new("program")
    .about("--this will get discarded--")
    .about("My program that does awesome stuff.  Check it out!")
    .build();

parser.parse_tokens(vec![].as_slice()).unwrap();
Examples found in repository?
examples/demo_sub_command.rs (line 11)
3fn main() {
4    let mut sub: u32 = 0;
5    let mut arg_0: bool = false;
6    let mut opt_0: bool = false;
7    let mut arg_1: bool = false;
8
9    let clp = CommandLineParser::new("sub-command");
10    let parser = clp
11        .about("Describe the base command line parser.  Let's make it a little long for fun.")
12        .branch(
13            Condition::new(Scalar::new(&mut sub), "sub")
14                // "0" is an undocumented sub-command.
15                // "1" is a regular sub-command.
16                .choice(1, "the one sub-command")
17                // "2" is a regular sub-command.
18                .choice(2, "the two sub-command")
19                // "3" is a false sub-command.
20                // It will appear in the documentation, but only those specified via `command(..)` actually affect the program structure.
21                .choice(3, "the three sub-command"),
22        )
23        .command(0, |sub_command| {
24            sub_command
25                .about("Describe the 0 sub-command parser.  Let's make it a little long for fun.")
26                .add(Parameter::argument(Scalar::new(&mut arg_0), "arg"))
27                .add(Parameter::option(
28                    Switch::new(&mut opt_0, true),
29                    "opt",
30                    None,
31                ))
32        })
33        .command(1, |sub_command| {
34            sub_command
35                .about("Describe the 1 sub-command parser.")
36                .add(Parameter::argument(Scalar::new(&mut arg_1), "arg"))
37        })
38        // Specify an argument-less & option-less sub-command by leaving the 'sub' untouched.
39        .command(2, |sub_command| sub_command)
40        // Since we never add "3", it isn't a true sub-command.
41        .build();
42
43    parser.parse();
44
45    println!("Used sub-command '{sub}'.");
46    match sub {
47        0 => {
48            println!("arg_0: {arg_0}");
49            println!("opt_0: {opt_0}");
50            assert!(!arg_1);
51        }
52        1 => {
53            assert!(!arg_0);
54            assert!(!opt_0);
55            println!("arg_1: {arg_1}");
56        }
57        2 => {
58            assert!(!arg_0);
59            assert!(!opt_0);
60            assert!(!arg_1);
61            println!("argument-less & option-less");
62        }
63        _ => {
64            panic!(
65                "impossible - the parser will reject any variants not specified via `command(..)`."
66            )
67        }
68    }
69}
Source

pub fn add<T>(self, parameter: Parameter<'a, T>) -> CommandLineParser<'a>

Add an argument/option to the command line parser.

The order of argument parameters corresponds to their positional order during parsing. The order of option parameters does not affect the command parser semantics.

§Example
use blarg::{CommandLineParser, Parameter, Scalar};

let mut a: u32 = 0;
let mut b: u32 = 0;
let parser = CommandLineParser::new("program")
    .add(Parameter::argument(Scalar::new(&mut a), "a"))
    .add(Parameter::argument(Scalar::new(&mut b), "b"))
    .build();

parser.parse_tokens(vec!["1", "2"].as_slice()).unwrap();

assert_eq!(a, 1);
assert_eq!(b, 2);
Examples found in repository?
examples/demo_summer_b.rs (lines 8-11)
3fn main() {
4    let mut items: Vec<u32> = Vec::default();
5
6    let clp = CommandLineParser::new("summer");
7    let parser = clp
8        .add(
9            Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
10                .help("The items to sum."),
11        )
12        .build();
13
14    parser.parse();
15    let sum: u32 = items.iter().sum();
16    println!("Sum: {sum}");
17}
More examples
Hide additional examples
examples/example.rs (lines 7-11)
2fn main() {
3    let mut verbose: bool = false;
4    let mut value: u32 = 0;
5    let ap = CommandLineParser::new("example");
6    let parser = ap
7        .add(Parameter::option(
8            Switch::new(&mut verbose, true),
9            "verbose",
10            Some('v'),
11        ))
12        .add(Parameter::argument(Scalar::new(&mut value), "value").meta(vec!["type: u32"]))
13        .build();
14    parser.parse();
15    println!("value: {value}, verbose: {verbose}");
16}
examples/demo_organization.rs (lines 35-39)
30fn parse_tokens(parse_fn: impl FnOnce(GeneralParser) -> Result<(), i32>) -> Params {
31    let mut params = Params::init();
32
33    let clp = CommandLineParser::new("organization");
34    let parser = clp
35        .add(Parameter::option(
36            Switch::new(&mut params.verbose, true),
37            "verbose",
38            Some('v'),
39        ))
40        .add(Parameter::argument(
41            Collection::new(&mut params.items, Nargs::AtLeastOne),
42            "item",
43        ))
44        .build();
45
46    // The parse_fn signature is a `Result`.
47    // However, since `GeneralParser::parse` does not return an error (it uses `std::process::exit` under the hood), the `Err` case is only reached via test.
48    parse_fn(parser).expect("test-reachable-only");
49    params
50}
examples/reducer.rs (lines 62-65)
53fn main() {
54    let mut _verbose: bool = false;
55    let mut operand: Operand = Operand::Add;
56    let mut initial: Option<u32> = None;
57    let mut _countries: HashSet<Country> = HashSet::default();
58    let mut items: Vec<u32> = Vec::default();
59
60    let ap = CommandLineParser::new("reducer");
61    let parser = ap
62        .add(
63            Parameter::option(Switch::new(&mut _verbose, true), "verbose", Some('v'))
64                .help("Do dee doo.  We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!"),
65        )
66        .add(
67            Parameter::option(Scalar::new(&mut operand), "operand", Some('o'))
68                .help("moot")
69                .choice(Operand::Add, "+")
70                .choice(Operand::Multiply, "*"),
71        )
72        .add(Parameter::option(Optional::new(&mut initial), "initial", None)
73            .meta(vec!["testing a really long meta.. abcdefghijklmnopqrstuvwxyz"])
74        )
75        .add(Parameter::option(Collection::new(&mut _countries, Nargs::AtLeastOne), "country", None))
76        .add(
77            Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
78                .help("The items."),
79        )
80        .build();
81    parser.parse();
82    println!("Items: {items:?}");
83    execute(_verbose, operand, initial, _countries, items);
84}
examples/foo_bar.rs (lines 63-66)
54fn main() {
55    let mut verbose: bool = false;
56    let mut foo_bar = FooBar::Foo;
57    let mut initial: Option<u32> = None;
58    let mut countries: HashSet<Country> = HashSet::default();
59    let mut items: Vec<u32> = Vec::default();
60
61    let ap = CommandLineParser::new("foo_bar");
62    let parser = ap
63        .add(
64            Parameter::option(Switch::new(&mut verbose, true), "verbose", Some('v'))
65                .help("Do dee doo."),
66        )
67        .branch(
68            Condition::new(Scalar::new(&mut foo_bar), "foo_bar")
69                .choice(FooBar::Foo, "123 abc let's make this one medium long.")
70                .choice(FooBar::Bar, "456 def let's make this one multiple sentences.  We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!")
71                .help("foo'y bar'y stuff")
72                .meta(vec!["a", "b", "c"]),
73        )
74        .command(FooBar::Foo, |sub| {
75            sub.add(Parameter::option(
76                Optional::new(&mut initial),
77                "initial",
78                None,
79            ))
80            .add(
81                Parameter::argument(Collection::new(&mut items, Nargs::Any), "item")
82                    .help("The items."),
83            )
84        })
85        .command(FooBar::Bar, |sub| {
86            sub.add(Parameter::option(
87                Collection::new(&mut countries, Nargs::AtLeastOne),
88                "country",
89                None,
90            ))
91        })
92        .build();
93    parser.parse();
94    println!("Items: {items:?}");
95    execute(verbose, foo_bar, initial, countries, items);
96}
Source

pub fn branch<T>(self, condition: Condition<'a, T>) -> SubCommandParser<'a, T>
where T: FromStr + Display + PartialEq,

Branch into a sub-command parser.

This changes the command line parser into a sub-command style command line parser. Any parameters added before the branch apply to the root parser.

Branching is always done with a special Scalar argument: Condition.

§Example
use blarg::{CommandLineParser, Parameter, Scalar, Condition};

let mut belongs_to_root: u32 = 0;
let mut sub_command: String = "".to_string();
let mut belongs_to_sub_command: u32 = 0;
let parser = CommandLineParser::new("program")
    .add(Parameter::argument(Scalar::new(&mut belongs_to_root), "belongs_to_root"))
    .branch(Condition::new(Scalar::new(&mut sub_command), "sub_command"))
    .command("the-command".to_string(), |sub| {
        sub.add(Parameter::argument(Scalar::new(&mut belongs_to_sub_command), "belongs_to_sub_command"))
    })
    .build();

parser.parse_tokens(vec!["1", "the-command", "2"].as_slice()).unwrap();

assert_eq!(belongs_to_root, 1);
assert_eq!(&sub_command, "the-command");
assert_eq!(belongs_to_sub_command, 2);
Examples found in repository?
examples/foo_bar.rs (lines 67-73)
54fn main() {
55    let mut verbose: bool = false;
56    let mut foo_bar = FooBar::Foo;
57    let mut initial: Option<u32> = None;
58    let mut countries: HashSet<Country> = HashSet::default();
59    let mut items: Vec<u32> = Vec::default();
60
61    let ap = CommandLineParser::new("foo_bar");
62    let parser = ap
63        .add(
64            Parameter::option(Switch::new(&mut verbose, true), "verbose", Some('v'))
65                .help("Do dee doo."),
66        )
67        .branch(
68            Condition::new(Scalar::new(&mut foo_bar), "foo_bar")
69                .choice(FooBar::Foo, "123 abc let's make this one medium long.")
70                .choice(FooBar::Bar, "456 def let's make this one multiple sentences.  We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!")
71                .help("foo'y bar'y stuff")
72                .meta(vec!["a", "b", "c"]),
73        )
74        .command(FooBar::Foo, |sub| {
75            sub.add(Parameter::option(
76                Optional::new(&mut initial),
77                "initial",
78                None,
79            ))
80            .add(
81                Parameter::argument(Collection::new(&mut items, Nargs::Any), "item")
82                    .help("The items."),
83            )
84        })
85        .command(FooBar::Bar, |sub| {
86            sub.add(Parameter::option(
87                Collection::new(&mut countries, Nargs::AtLeastOne),
88                "country",
89                None,
90            ))
91        })
92        .build();
93    parser.parse();
94    println!("Items: {items:?}");
95    execute(verbose, foo_bar, initial, countries, items);
96}
More examples
Hide additional examples
examples/dynamic_sub_command.rs (line 24)
4fn main() {
5    let contains_dynamic_x = env::var("DYNAMIC_X").is_ok();
6    let contains_dynamic_y = env::var("DYNAMIC_Y").is_ok();
7
8    let mut sub: u32 = 0;
9    let mut arg_0: bool = false;
10    let mut arg_1: bool = false;
11    let mut arg_2: bool = false;
12
13    let mut condition = Condition::new(Scalar::new(&mut sub), "sub")
14        // "0" is an undocumented sub-command, but will only available when environment contains `DYNAMIC_X`.
15        // "1" is a regular sub-command.
16        .choice(1, "the one sub-command");
17
18    if contains_dynamic_y {
19        // "2" is a sub-command that will only be available when the environment contains `DYNAMIC_Y`.
20        condition = condition.choice(2, "the two sub-command");
21    }
22
23    let clp = CommandLineParser::new("sub-command");
24    let mut clp = clp.branch(condition).command(1, |sub_command| {
25        sub_command.add(Parameter::argument(Scalar::new(&mut arg_1), "arg"))
26    });
27
28    if contains_dynamic_x {
29        clp = clp.command(0, |sub_command| {
30            sub_command.add(Parameter::argument(Scalar::new(&mut arg_0), "arg"))
31        });
32    }
33
34    if contains_dynamic_y {
35        clp = clp.command(2, |sub_command| {
36            sub_command.add(Parameter::argument(Scalar::new(&mut arg_2), "arg"))
37        });
38    }
39
40    let parser = clp.build();
41
42    parser.parse();
43
44    println!("Used sub-command '{sub}'.");
45    match sub {
46        0 => {
47            println!("arg_0: {arg_0}");
48            assert!(!arg_1);
49            assert!(!arg_2);
50        }
51        1 => {
52            assert!(!arg_0);
53            println!("arg_1: {arg_1}");
54            assert!(!arg_2);
55        }
56        2 => {
57            assert!(!arg_0);
58            assert!(!arg_1);
59            println!("arg_2: {arg_2}");
60        }
61        _ => {
62            panic!("impossible - the parser will reject any variants not specified via `add(..)`.")
63        }
64    }
65}
examples/demo_sub_command.rs (lines 12-22)
3fn main() {
4    let mut sub: u32 = 0;
5    let mut arg_0: bool = false;
6    let mut opt_0: bool = false;
7    let mut arg_1: bool = false;
8
9    let clp = CommandLineParser::new("sub-command");
10    let parser = clp
11        .about("Describe the base command line parser.  Let's make it a little long for fun.")
12        .branch(
13            Condition::new(Scalar::new(&mut sub), "sub")
14                // "0" is an undocumented sub-command.
15                // "1" is a regular sub-command.
16                .choice(1, "the one sub-command")
17                // "2" is a regular sub-command.
18                .choice(2, "the two sub-command")
19                // "3" is a false sub-command.
20                // It will appear in the documentation, but only those specified via `command(..)` actually affect the program structure.
21                .choice(3, "the three sub-command"),
22        )
23        .command(0, |sub_command| {
24            sub_command
25                .about("Describe the 0 sub-command parser.  Let's make it a little long for fun.")
26                .add(Parameter::argument(Scalar::new(&mut arg_0), "arg"))
27                .add(Parameter::option(
28                    Switch::new(&mut opt_0, true),
29                    "opt",
30                    None,
31                ))
32        })
33        .command(1, |sub_command| {
34            sub_command
35                .about("Describe the 1 sub-command parser.")
36                .add(Parameter::argument(Scalar::new(&mut arg_1), "arg"))
37        })
38        // Specify an argument-less & option-less sub-command by leaving the 'sub' untouched.
39        .command(2, |sub_command| sub_command)
40        // Since we never add "3", it isn't a true sub-command.
41        .build();
42
43    parser.parse();
44
45    println!("Used sub-command '{sub}'.");
46    match sub {
47        0 => {
48            println!("arg_0: {arg_0}");
49            println!("opt_0: {opt_0}");
50            assert!(!arg_1);
51        }
52        1 => {
53            assert!(!arg_0);
54            assert!(!opt_0);
55            println!("arg_1: {arg_1}");
56        }
57        2 => {
58            assert!(!arg_0);
59            assert!(!opt_0);
60            assert!(!arg_1);
61            println!("argument-less & option-less");
62        }
63        _ => {
64            panic!(
65                "impossible - the parser will reject any variants not specified via `command(..)`."
66            )
67        }
68    }
69}
Source

pub fn build_parser(self) -> Result<GeneralParser<'a>, ConfigError>

Build the command line parser as a Result. This finalizes the configuration and checks for errors (ex: a repeated parameter name).

Source

pub fn build(self) -> GeneralParser<'a>

Build the command line parser. This finalizes the configuration and checks for errors (ex: a repeated parameter name). If an error is encountered, exits with error code 1 (via std::process::exit).

Examples found in repository?
examples/empty.rs (line 5)
3fn main() {
4    let ap = CommandLineParser::new("empty");
5    let parser = ap.build();
6    parser.parse();
7    println!("empty parser");
8}
More examples
Hide additional examples
examples/demo_summer_b.rs (line 12)
3fn main() {
4    let mut items: Vec<u32> = Vec::default();
5
6    let clp = CommandLineParser::new("summer");
7    let parser = clp
8        .add(
9            Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
10                .help("The items to sum."),
11        )
12        .build();
13
14    parser.parse();
15    let sum: u32 = items.iter().sum();
16    println!("Sum: {sum}");
17}
examples/example.rs (line 13)
2fn main() {
3    let mut verbose: bool = false;
4    let mut value: u32 = 0;
5    let ap = CommandLineParser::new("example");
6    let parser = ap
7        .add(Parameter::option(
8            Switch::new(&mut verbose, true),
9            "verbose",
10            Some('v'),
11        ))
12        .add(Parameter::argument(Scalar::new(&mut value), "value").meta(vec!["type: u32"]))
13        .build();
14    parser.parse();
15    println!("value: {value}, verbose: {verbose}");
16}
examples/demo_organization.rs (line 44)
30fn parse_tokens(parse_fn: impl FnOnce(GeneralParser) -> Result<(), i32>) -> Params {
31    let mut params = Params::init();
32
33    let clp = CommandLineParser::new("organization");
34    let parser = clp
35        .add(Parameter::option(
36            Switch::new(&mut params.verbose, true),
37            "verbose",
38            Some('v'),
39        ))
40        .add(Parameter::argument(
41            Collection::new(&mut params.items, Nargs::AtLeastOne),
42            "item",
43        ))
44        .build();
45
46    // The parse_fn signature is a `Result`.
47    // However, since `GeneralParser::parse` does not return an error (it uses `std::process::exit` under the hood), the `Err` case is only reached via test.
48    parse_fn(parser).expect("test-reachable-only");
49    params
50}
examples/reducer.rs (line 80)
53fn main() {
54    let mut _verbose: bool = false;
55    let mut operand: Operand = Operand::Add;
56    let mut initial: Option<u32> = None;
57    let mut _countries: HashSet<Country> = HashSet::default();
58    let mut items: Vec<u32> = Vec::default();
59
60    let ap = CommandLineParser::new("reducer");
61    let parser = ap
62        .add(
63            Parameter::option(Switch::new(&mut _verbose, true), "verbose", Some('v'))
64                .help("Do dee doo.  We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!"),
65        )
66        .add(
67            Parameter::option(Scalar::new(&mut operand), "operand", Some('o'))
68                .help("moot")
69                .choice(Operand::Add, "+")
70                .choice(Operand::Multiply, "*"),
71        )
72        .add(Parameter::option(Optional::new(&mut initial), "initial", None)
73            .meta(vec!["testing a really long meta.. abcdefghijklmnopqrstuvwxyz"])
74        )
75        .add(Parameter::option(Collection::new(&mut _countries, Nargs::AtLeastOne), "country", None))
76        .add(
77            Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
78                .help("The items."),
79        )
80        .build();
81    parser.parse();
82    println!("Items: {items:?}");
83    execute(_verbose, operand, initial, _countries, items);
84}

Auto Trait Implementations§

§

impl<'a> Freeze for CommandLineParser<'a>

§

impl<'a> !RefUnwindSafe for CommandLineParser<'a>

§

impl<'a> !Send for CommandLineParser<'a>

§

impl<'a> !Sync for CommandLineParser<'a>

§

impl<'a> Unpin for CommandLineParser<'a>

§

impl<'a> !UnwindSafe for CommandLineParser<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more