January 2019
Intermediate to advanced
520 pages
14h 32m
English
Some popular applications, such as cargo and docker, use subcommands to provide multiple commands inside a single binary. We can also support subcommands with the clap crate. A microservice might have two commands: one to run the server and one to generate a secret for the HTTP cookies. Take a look at the following code:
let matches = App::new("Server with keys") .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand(SubCommand::with_name("run") .about("run the server") .arg(Arg::with_name("address") .short("a") .long("address") .takes_value(true) .help("address of the server")) .subcommand(SubCommand::with_name("key") .about("generates a secret key for cookies"))) .get_matches();
Here, we have used two methods. ...
Read now
Unlock full access