January 2019
Intermediate to advanced
520 pages
14h 32m
English
Our tool expects two subcommands: add and list. Let's add them to a clap::App instance. Like all previous examples, we also added a --database argument to set the connection URL. Look at the following code:
let matches = App::new(crate_name!()) .version(crate_version!()) .author(crate_authors!()) .about(crate_description!()) .setting(AppSettings::SubcommandRequired) .arg( Arg::with_name("database") .short("d") .long("db") .value_name("ADDR") .help("Sets an address of db connection") .takes_value(true), ) .subcommand(SubCommand::with_name(CMD_ADD).about("add user to the table") .arg(Arg::with_name("USER_ID") .help("Sets the id of a user") .required(true) .index(1)) .arg(Arg::with_name("ACTIVITY") .help("Sets the activity ...Read now
Unlock full access