gpt4 book ai didi

rust - 使用 clap 3 derive 宏,我如何指定必须至少存在一个组的参数?

转载 作者:行者123 更新时间:2023-12-05 06:00:13 32 4
gpt4 key购买 nike

我有一个拍手结构如下:

#[derive(Clap)]
#[clap(
version = "0.1.0",
author = "..."
)]
pub struct Cli {
#[clap(long)]
arg_a: Option<String>,

#[clap(long)]
arg_b: Option<String>,

#[clap(long)]
arg_c: Option<String>,

#[clap(long)]
other_arguments: Option<usize>,
}

我如何指定至少必须存在 {arg_a, arg_b, arg_c} 之一,但还可以存在更多?

最佳答案

您可以在 https://github.com/clap-rs/clap/blob/v3.1.14/examples/tutorial_derive/README.md#argument-relations 阅读有关参数关系的信息

添加例如:

#[clap(group(
ArgGroup::new("my-group")
.required(true)
.args(&["arg-a", "arg-b", "arg-c"]),
))]

https://docs.rs/clap/latest/clap/struct.ArgGroup.html#method.required “解析时需要来自组的参数。”

关于rust - 使用 clap 3 derive 宏,我如何指定必须至少存在一个组的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67803027/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com