зеркало из https://github.com/mozilla/gecko-dev.git
40 строки
1.2 KiB
Rust
40 строки
1.2 KiB
Rust
extern crate docopt;
|
|
|
|
use docopt::Docopt;
|
|
|
|
const USAGE: &'static str = "
|
|
Naval Fate.
|
|
|
|
Usage:
|
|
naval_fate.py ship new <name>...
|
|
naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
|
|
naval_fate.py ship shoot <x> <y>
|
|
naval_fate.py mine (set|remove) <x> <y> [--moored | --drifting]
|
|
naval_fate.py (-h | --help)
|
|
naval_fate.py --version
|
|
|
|
Options:
|
|
-h --help Show this screen.
|
|
--version Show version.
|
|
--speed=<kn> Speed in knots [default: 10].
|
|
--moored Moored (anchored) mine.
|
|
--drifting Drifting mine.
|
|
";
|
|
|
|
fn main() {
|
|
let version = "1.2.3".to_owned();
|
|
let args = Docopt::new(USAGE)
|
|
.and_then(|dopt| dopt.version(Some(version)).parse())
|
|
.unwrap_or_else(|e| e.exit());
|
|
println!("{:?}", args);
|
|
|
|
// You can conveniently access values with `get_{bool,count,str,vec}`
|
|
// functions. If the key doesn't exist (or if, e.g., you use `get_str` on
|
|
// a switch), then a sensible default value is returned.
|
|
println!("\nSome values:");
|
|
println!(" Speed: {}", args.get_str("--speed"));
|
|
println!(" Drifting? {}", args.get_bool("--drifting"));
|
|
println!(" Names: {:?}", args.get_vec("<name>"));
|
|
println!(" Command 'ship' invoked? {:?}", args.get_bool("ship"));
|
|
}
|