numeric_prefix/
numeric_prefix.rs

1/// You can parse multiple positional elements with earlier being optional as well
2/// This example takes two - optional numeric prefix and a command name:
3///
4/// > numeric_prefix 8 work
5/// Options { prefix: Some(8), command: "work" }
6///
7/// > numeric_prefix sleep
8/// Options { prefix: None, command: "sleep" }
9///
10/// Generated usage reflects that:
11/// Usage: numeric_prefix [PREFIX] COMMAND
12use bpaf::*;
13
14#[derive(Debug, Clone)]
15#[allow(dead_code)]
16pub struct Options {
17    prefix: Option<usize>,
18    command: String,
19}
20
21pub fn options() -> OptionParser<Options> {
22    let prefix = positional::<usize>("PREFIX")
23        .help("Optional numeric command prefix")
24        .optional()
25        .catch();
26    let command = positional::<String>("COMMAND").help("Required command name");
27
28    construct!(Options { prefix, command }).to_options()
29}
30
31fn main() {
32    println!("{:#?}", options().run());
33}