有没有办法让 clap 覆盖 [ -h | --help ] 标记帮助文本?
Is there a way to make clap override the [ -h | --help ] flags help text?
我正在关注 Rust Clap Package 文档中的示例代码,但找不到有关自动生成标志 [-h 和 --help] 的帮助文本的任何参考。
extern crate clap;
use clap::{App, Arg, SubCommand};
fn main() {
let matches = App::new("Command One")
.version("1.0")
.author("Some Author <the_account@provider.com>")
.about("Descripción del comando.")
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("Sets a custom config file")
.takes_value(true))
.arg(Arg::with_name("INPUT")
.help("Sets the input file to use")
.required(true)
.index(1))
.arg(Arg::with_name("v")
.short("v")
.multiple(true)
.help("Sets the level of verbosity"))
// *** I'm trying this ***
.arg(Arg::with_name("help")
.short("h")
.long("help")
.help("A new help text."))
// ***********
.subcommand(SubCommand::with_name("test")
.about("controls testing features")
.version("1.3")
.author("Someone E. <someone_else@other.com>")
.arg(Arg::with_name("debug")
.short("d")
.help("print debug information verbosely")))
.get_matches();
let config = matches.value_of("config").unwrap_or("default.conf");
println!("Value for config: {}", config);
println!("Using input file: {}", matches.value_of("INPUT").unwrap());
match matches.occurrences_of("v") {
0 => println!("No verbose info"),
1 => println!("Some verbose info"),
2 => println!("Tons of verbose info"),
3 | _ => println!("Don't be crazy"),
}
if let Some(matches) = matches.subcommand_matches("test") {
if matches.is_present("debug") {
println!("Printing debug info...");
} else {
println!("Printing normally...");
}
}
}
要更改帮助文本中 -h
/--help
参数的说明,请使用 help_message
method. Likewise, to change the description of -V
/--version
, use version_message
.
extern crate clap;
use clap::App;
fn main() {
let matches = App::new("app")
.help_message("this is the help command")
.version_message("this is the version command")
.get_matches_from(&["app", "--help"]);
}
输出:
app
USAGE:
app
FLAGS:
-h, --help this is the help command
-V, --version this is the version command
我正在关注 Rust Clap Package 文档中的示例代码,但找不到有关自动生成标志 [-h 和 --help] 的帮助文本的任何参考。
extern crate clap;
use clap::{App, Arg, SubCommand};
fn main() {
let matches = App::new("Command One")
.version("1.0")
.author("Some Author <the_account@provider.com>")
.about("Descripción del comando.")
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("Sets a custom config file")
.takes_value(true))
.arg(Arg::with_name("INPUT")
.help("Sets the input file to use")
.required(true)
.index(1))
.arg(Arg::with_name("v")
.short("v")
.multiple(true)
.help("Sets the level of verbosity"))
// *** I'm trying this ***
.arg(Arg::with_name("help")
.short("h")
.long("help")
.help("A new help text."))
// ***********
.subcommand(SubCommand::with_name("test")
.about("controls testing features")
.version("1.3")
.author("Someone E. <someone_else@other.com>")
.arg(Arg::with_name("debug")
.short("d")
.help("print debug information verbosely")))
.get_matches();
let config = matches.value_of("config").unwrap_or("default.conf");
println!("Value for config: {}", config);
println!("Using input file: {}", matches.value_of("INPUT").unwrap());
match matches.occurrences_of("v") {
0 => println!("No verbose info"),
1 => println!("Some verbose info"),
2 => println!("Tons of verbose info"),
3 | _ => println!("Don't be crazy"),
}
if let Some(matches) = matches.subcommand_matches("test") {
if matches.is_present("debug") {
println!("Printing debug info...");
} else {
println!("Printing normally...");
}
}
}
要更改帮助文本中 -h
/--help
参数的说明,请使用 help_message
method. Likewise, to change the description of -V
/--version
, use version_message
.
extern crate clap;
use clap::App;
fn main() {
let matches = App::new("app")
.help_message("this is the help command")
.version_message("this is the version command")
.get_matches_from(&["app", "--help"]);
}
输出:
app
USAGE:
app
FLAGS:
-h, --help this is the help command
-V, --version this is the version command