hashmap/
hashmap.rs

1use docopt::Docopt;
2
3const USAGE: &'static str = "
4Naval Fate.
5
6Usage:
7  naval_fate.py ship new <name>...
8  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
9  naval_fate.py ship shoot <x> <y>
10  naval_fate.py mine (set|remove) <x> <y> [--moored | --drifting]
11  naval_fate.py (-h | --help)
12  naval_fate.py --version
13
14Options:
15  -h --help     Show this screen.
16  --version     Show version.
17  --speed=<kn>  Speed in knots [default: 10].
18  --moored      Moored (anchored) mine.
19  --drifting    Drifting mine.
20";
21
22fn main() {
23    let version = "1.2.3".to_owned();
24    let args = Docopt::new(USAGE)
25                      .and_then(|dopt| dopt.version(Some(version)).parse())
26                      .unwrap_or_else(|e| e.exit());
27    println!("{:?}", args);
28
29    // You can conveniently access values with `get_{bool,count,str,vec}`
30    // functions. If the key doesn't exist (or if, e.g., you use `get_str` on
31    // a switch), then a sensible default value is returned.
32    println!("\nSome values:");
33    println!("  Speed: {}", args.get_str("--speed"));
34    println!("  Drifting? {}", args.get_bool("--drifting"));
35    println!("  Names: {:?}", args.get_vec("<name>"));
36    println!("  Command 'ship' invoked? {:?}", args.get_bool("ship"));
37}