pub fn run<I, S>(argv: I) -> Result<(), Error>
    where I: IntoIterator<Item=S>,
          S: AsRef<str>,
{
    let cmd_args: Vec<String> = argv.into_iter()
        .map(|arg| arg.as_ref().into())
        .collect();

    let mut dispatch_args = vec![];

    for (i, arg) in cmd_args.iter().enumerate() {
        dispatch_args.push(arg.clone());

        if i > 0 && arg.chars().next() != Some('-') {
            // Found the cmd, done
            break;
        }
    }


    // Create a opt parser from the top level usage
    let docopt = try!(Docopt::new(USAGE))
        .help(false)
        .argv(dispatch_args);

    // Extract the command and args
    let args = match docopt.parse() {
        Ok(args) => args,
        Err(e) => return Err(e.into()),
    };

    // Handle help requests
    if args.get_bool("-h") {
        println!("{}", USAGE);
        return Ok(());
    }

    if args.get_bool("--version") {
        println!("dotbc {}", super::VERSION);
        return Ok(());
    }

    // Dispatch to the subcommand
    match args.get_str("<cmd>") {
        "ls-files" => ls_files::run(cmd_args),
        "read-file" => read_file::run(cmd_args),
        "write-file" => write_file::run(cmd_args),
        "show-metadata" => show_metadata::run(cmd_args),
        _ => {
            // Unknown command
            unimplemented!();
        }
    }
}
/// Run the command specified with the given set of arguments
Run the command specified with the given set of arguments
Run the command specified with the given set of arguments
pub fn run<I, S>(argv: I) -> Result<(), Error>
    where I: IntoIterator<Item=S>,
          S: AsRef<str>,
{
    let cmd_args: Vec<String> = argv.into_iter()
        .map(|arg| arg.as_ref().into())
        .collect();
    let mut dispatch_args = vec![];
    for (i, arg) in cmd_args.iter().enumerate() {
        dispatch_args.push(arg.clone());
        if i > 0 && arg.chars().next() != Some('-') {
            // Found the cmd, done
            break;
        }
    }
    // Create a opt parser from the top level usage
    let docopt = try!(Docopt::new(USAGE))
        .help(false)
        .argv(dispatch_args);
    // Extract the command and args
    let args = match docopt.parse() {
        Ok(args) => args,
        Err(e) => return Err(e.into()),
    };
    // Handle help requests
    if args.get_bool("-h") {
        println!("{}", USAGE);
        return Ok(());
    }
    if args.get_bool("--version") {
        println!("dotbc {}", super::VERSION);
        return Ok(());
    }
    // Dispatch to the subcommand
    match args.get_str("<cmd>") {
        "ls-files" => ls_files::run(cmd_args),
        "read-file" => read_file::run(cmd_args),
        "write-file" => write_file::run(cmd_args),
        "show-metadata" => show_metadata::run(cmd_args),
        _ => {
            // Unknown command
            unimplemented!();
        }
    }
}
pub fn run < I , S > ( argv : I ) -> Result < ( ) , Error > where I : IntoIterator < Item = S > , S : AsRef < str > , { let cmd_args : Vec < String > = argv . into_iter ( ) . map ( | arg | arg . as_ref ( ) . into ( ) ) . collect ( ) ; let mut dispatch_args = vec ! [ ] ; for ( i , arg ) in cmd_args . iter ( ) . enumerate ( ) { dispatch_args . push ( arg . clone ( ) ) ; if i > 0 && arg . chars ( ) . next ( ) != Some ( '-' ) { // Found the cmd, done break ; } } // Create a opt parser from the top level usage let docopt = try ! ( Docopt new ( USAGE ) ) . help ( false ) . argv ( dispatch_args ) ; // Extract the command and args let args = match docopt . parse ( ) { Ok ( args ) => args , Err ( e ) => return Err ( e . into ( ) ) , } ; // Handle help requests if args . get_bool ( " " ) { println ! ( " " USAGE ) ; return Ok ( ( ) ) ; } if args . get_bool ( " " ) { println ! ( " " super VERSION ) ; return Ok ( ( ) ) ; } // Dispatch to the subcommand match args . get_str ( " " ) { " " => ls_files :: run ( cmd_args ) , " " => read_file :: run ( cmd_args ) , " " => write_file :: run ( cmd_args ) , " " => show_metadata :: run ( cmd_args ) , _ => { // Unknown command unimplemented ! ( ) ; } } }
Run the command specified with the given set of arguments
Run the command specified with the given set of arguments
argv
I
argv
I