docopt 0.6.86

Command line argument parsing.
extern crate rustc_serialize;
extern crate docopt;

use docopt::Docopt;

// Write the Docopt usage string.
const USAGE: &'static str = "
Rust's package manager

    cargo <command> [<args>...]
    cargo [options]

    -h, --help       Display this message
    -V, --version    Print version info and exit
    --list           List installed commands
    -v, --verbose    Use verbose output

Some common cargo commands are:
    build       Compile the current project
    clean       Remove the target directory
    doc         Build this project's and its dependencies' documentation
    new         Create a new cargo project
    run         Build and execute src/
    test        Run the tests
    bench       Run the benchmarks
    update      Update dependencies listed in Cargo.lock

See 'cargo help <command>' for more information on a specific command.

#[derive(Debug, RustcDecodable)]
struct Args {
    arg_command: Option<Command>,
    arg_args: Vec<String>,
    flag_list: bool,
    flag_verbose: bool,

#[derive(Debug, RustcDecodable)]
enum Command {
    Build, Clean, Doc, New, Run, Test, Bench, Update,

fn main() {
    let args: Args = Docopt::new(USAGE)
                            .and_then(|d| d.options_first(true).decode())
                            .unwrap_or_else(|e| e.exit());
    println!("{:?}", args);