Command line 如何通过Clap将所有命令行参数传递给另一个程序?
我有一个用于处理命令参数解析的程序foo。foo调用另一个程序bar。最近,我决定foo的用户如果愿意,应该能够将参数传递给bar。我将bar命令添加到Clap:Command line 如何通过Clap将所有命令行参数传递给另一个程序?,command-line,rust,clap,Command Line,Rust,Clap,我有一个用于处理命令参数解析的程序foo。foo调用另一个程序bar。最近,我决定foo的用户如果愿意,应该能够将参数传递给bar。我将bar命令添加到Clap: let matches = App::new("Foo") .arg(Arg::with_name("file").value_name("FILE").required(true)) .arg( Arg::with_name("bar") .value_name("[BAR_O
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();
当我尝试将命令-baz=3传递给bar时,如下所示:
./foo-b-baz=3 file.txt
或
./foo-b-baz=3 file.txt
clap返回此错误:
错误:找到参数'-b',该参数不是预期的,或者在此上下文中无效
如何通过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]")
.allow_hyphen_values(true)
.short("b")
.long("bar")
.multiple(true)
.help("Invoke bar with these options"),
)
.get_matches();