Replies: 2 comments 2 replies
-
There is a secondary use case that is somewhat similar. I want to collect key-value pairs from the CLI with the use of two parameters that could be provided multiple times: #[derive(Parser)]
#[command(version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
MyCommand {
#[arg(short, long)]
key: usize,
#[arg(short, long)]
value: usize
}
}
fn main() {
let args = Cli::parse();
...
} The program could be called like this:
This however requires that for every |
Beta Was this translation helpful? Give feedback.
-
Almost everything clap uses for writing its error messges is publicly exposed though not thoroughly documented. This is kind of a "left to the user" exercise than something I expect we'll invest a lot in documenting. See https://docs.rs/clap/latest/clap/error/struct.Error.html In particular, see the |
Beta Was this translation helpful? Give feedback.
-
I am using
#[derive(Parser)]
and#[derive(Subcommand)]
:I want to validate the value of
MyCommand.param
against a value that is only known during runtime. I can of course do that without blending inclap
but it would be nice to get consistent error messages for invalid arguments.The closest I got so far is the code below, but the error message that is printed doesn't have any context about which command was specified and which command parameter had an invalid value.
Beta Was this translation helpful? Give feedback.
All reactions