1use docopt::Docopt;
2use serde::Deserialize;
3
4const USAGE: &'static str = "
6Rust's package manager
7
8Usage:
9 cargo <command> [<args>...]
10 cargo [options]
11
12Options:
13 -h, --help Display this message
14 -V, --version Print version info and exit
15 --list List installed commands
16 -v, --verbose Use verbose output
17
18Some common cargo commands are:
19 build Compile the current project
20 clean Remove the target directory
21 doc Build this project's and its dependencies' documentation
22 new Create a new cargo project
23 run Build and execute src/main.rs
24 test Run the tests
25 bench Run the benchmarks
26 update Update dependencies listed in Cargo.lock
27
28See 'cargo help <command>' for more information on a specific command.
29";
30
31#[derive(Debug, Deserialize)]
32struct Args {
33 arg_command: Option<Command>,
34 arg_args: Vec<String>,
35 flag_list: bool,
36 flag_verbose: bool,
37}
38
39#[derive(Debug, Deserialize)]
40enum Command {
41 Build,
42 Clean,
43 Doc,
44 New,
45 Run,
46 Test,
47 Bench,
48 Update,
49}
50
51fn main() {
52 let args: Args = Docopt::new(USAGE)
53 .and_then(|d| d.options_first(true).deserialize())
54 .unwrap_or_else(|e| e.exit());
55 println!("{:?}", args);
56}