-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
C-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectations
Description
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
Clap Version
4.1.6
Describe your use case
I want to set an arguments default value, using default_value_ifs()
depending on multiple other arguments.
For example, in the code below, I would like to change the value for destination depending on the value of data_type
(since in actual usage the UDP port depends on the type of data we're sending).
#[derive(Debug, clap::Parser)]
#[command(
long_about = None,
long_version(crate::build_info::BUILD_INFO.long_version_string(),
))]
pub(crate) struct Cli {
#[arg(value_enum)]
// Which data type to send
pub(crate) data_type: DataType,
#[arg(value_enum)]
// How to send
pub(crate) sender: Sender,
#[arg(
short,
long,
default_value_ifs([
("sender", clap::builder::ArgPredicate::Equals("nats".into()), "localhost:4222"),
("sender", clap::builder::ArgPredicate::Equals("udp".into()), "localhost:8585")
]),
)]
/// Where to send
pub destination: String,
}
Describe the solution you'd like
The idea is to expand ArgPredicate
to look something like this:
pub enum ArgPredicate {
IsPresent,
Equals(OsStr),
And(ArgPredicate, ArgPredicate),
Or(ArgPredicate, ArgPredicate),
}
Alternatives, if applicable
No idea
Additional Context
No response
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectations