     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97

    use vec_map::VecMap;

    use args::{ArgMatches, MatchedArg, SubCommand};
    use std::collections::hash_map::{Entry, Keys, Iter};

    pub struct ArgMatcher<'ar>(ArgMatches<'ar, 'ar>);

    impl<'ar> ArgMatcher<'ar> {
        pub fn new() -> Self {
            ArgMatcher(ArgMatches::new())
        }

        pub fn get_mut(&mut self, arg: &str) -> Option<&mut MatchedArg> {
            self.0.args.get_mut(arg)
        }

        pub fn get(&self, arg: &str) -> Option<&MatchedArg> {
            self.0.args.get(arg)
        }

        pub fn remove(&mut self, arg: &str) {
            self.0.args.remove(arg);
        }

        pub fn insert(&mut self, name: &'ar str) {
            self.0.args.insert(name, MatchedArg::new());
        }

        pub fn contains(&self, arg: &str) -> bool {
            self.0.args.contains_key(arg)
        }

        pub fn is_empty(&self) -> bool {
            self.0.args.is_empty()
        }

        pub fn values_of(&self, arg: &str) -> Option<Vec<&str>> {
            self.0.values_of(arg)
        }

        pub fn usage(&mut self, usage: String) {
            self.0.usage = Some(usage);
        }

        pub fn arg_names(&self) -> Keys<&'ar str, MatchedArg> {
            self.0.args.keys()
        }

        pub fn entry(&mut self, arg: &'ar str) -> Entry<&'ar str, MatchedArg> {
            self.0.args.entry(arg)
        }

        pub fn subcommand(&mut self, sc: SubCommand<'ar, 'ar>) {
            self.0.subcommand = Some(Box::new(sc));
        }

        pub fn subcommand_name(&self) -> Option<&str> {
            self.0.subcommand_name()
        }

        pub fn iter(&self) -> Iter<&'ar str, MatchedArg> {
            self.0.args.iter()
        }

        pub fn inc_occurrence_of(&mut self, arg: &'ar str) {
            if let Some(a) = self.get_mut(arg) {
                a.occurrences += 1;
                return;
            }
            self.insert(arg);
        }

        pub fn inc_occurrences_of(&mut self, args: &[&'ar str]) {
            for arg in args {
                self.inc_occurrence_of(arg);
            }
        }

        pub fn add_val_to(&mut self, arg: &'ar str, val: String) {
            let ma = self.entry(arg).or_insert(MatchedArg {
                // occurrences will be incremented on getting a value
                occurrences: 0,
                values: Some(VecMap::new()),
            });
            if let Some(ref mut vals) = ma.values {
                let len = vals.len() + 1;
                vals.insert(len, val);
                ma.occurrences += 1;
            }
        }
    }

    impl<'ar> Into<ArgMatches<'ar, 'ar>> for ArgMatcher<'ar> {
        fn into(self) -> ArgMatches<'ar, 'ar> {
            self.0
        }
    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)