繁体   English   中英

如何通过Clap将所有命令行参数传递给另一个程序?

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

我有一个使用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_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返回此错误:

error: Found argument '-b' which wasn't expected, or isn't valid in this context

如何通过Clap传送命令?

如果参数bar的值本身可能以连字符开头,那么您需要设置allow_hyphen_values选项:

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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM