clap

Method call on clap::App moving ownership more than once

戏子无情 提交于 2020-01-15 07:48:28
问题 Even after reading the chapters about reference ownership and borrowing, I cannot understand some things in the following code, effectively stopping me from calling more than one method from clap::App ! extern crate clap; use clap::App; fn main() { let mut app = App::new("name me").args_from_usage("<input_file> 'Sets the input file to use'"); let matches = app.get_matches(); app.print_help(); println!( "Using input file: {}", matches.value_of("input_file").unwrap() ); } Compiling this code

Method call on clap::App moving ownership more than once

柔情痞子 提交于 2020-01-15 07:48:25
问题 Even after reading the chapters about reference ownership and borrowing, I cannot understand some things in the following code, effectively stopping me from calling more than one method from clap::App ! extern crate clap; use clap::App; fn main() { let mut app = App::new("name me").args_from_usage("<input_file> 'Sets the input file to use'"); let matches = app.get_matches(); app.print_help(); println!( "Using input file: {}", matches.value_of("input_file").unwrap() ); } Compiling this code

How can I pass all command line arguments through Clap to another program?

为君一笑 提交于 2019-12-24 18:53:13
问题 I have a program foo that uses Clap to handle command argument parsing. foo invokes another program, bar . Recently, I decided that users of foo should be able to pass arguments to bar if they like. I added the bar command to Clap: let matches = App::new("Foo") .arg(Arg::with_name("file").value_name("FILE").required(true)) .arg( Arg::with_name("bar") .value_name("[BAR_OPTIONS]") .short("b") .long("bar") .multiple(true) .help("Invoke bar with these options"), ) .get_matches(); When I try to

Is there any straightforward way for Clap to display help when no command is provided?

本小妞迷上赌 提交于 2019-12-22 04:46:15
问题 I'm using the Clap crate for parsing command line parameters. I've defined a subcommand ls that should list files. Clap also defines a help subcommand that displays information about the application and its usage. If no command is provided, nothing gets displayed at all, but I want the app to display help in that case. I've tried this code, which looks pretty straightforward, but it doesn't work: extern crate clap; use clap::{App, SubCommand}; fn main() { let mut app = App::new("myapp")

Is there any straightforward way for Clap to display help when no command is provided?

丶灬走出姿态 提交于 2019-12-05 06:06:06
I'm using the Clap crate for parsing command line parameters. I've defined a subcommand ls that should list files. Clap also defines a help subcommand that displays information about the application and its usage. If no command is provided, nothing gets displayed at all, but I want the app to display help in that case. I've tried this code, which looks pretty straightforward, but it doesn't work: extern crate clap; use clap::{App, SubCommand}; fn main() { let mut app = App::new("myapp") .version("0.0.1") .about("My first CLI APP") .subcommand(SubCommand::with_name("ls").about("List anything"))