对于我的生锈程序,我使用Clap来解析命令行参数。我想让用户输入这样的标志:
my_program -L testfile.txt我的结构是这样设置的:
struct Args {
#[arg(short)]
L: bool,
#[arg(short)]
s: bool,
name: String,
}当我测试我的程序时,它会给出以下错误:
error: Found argument '-L' which wasn't expected, or isn't valid in this context.我也不能使用ignore_case(),因为这是一个标志,不带值。
有人知道如何解决这个问题吗?
发布于 2022-09-29 01:53:04
从clap中的Arg属性派生文档:
short [= <char>]:Arg::short
<char>:默认为大小写转换字段名中的第一个字符。use clap::Parser;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[arg(short = 'L')]
L: bool,
#[arg(short)]
s: bool,
name: String,
}
fn main() {
let args = Cli::parse();
}构建的可执行帮助:
Usage: xxxxxx [OPTIONS] <NAME>
Arguments:
<NAME>
Options:
-L
-s
-h, --help Print help information
-V, --version Print version informationhttps://stackoverflow.com/questions/73889392
复制相似问题