Replies: 1 comment 3 replies
-
I gave the following a quick try #!/usr/bin/env nargo
---
[dependencies]
clap = { version = "4", features = ["derive"] }
---
use clap::Parser;
#[derive(Parser, Debug)]
#[command(group = clap::ArgGroup::new("final"))]
struct Cli {
#[arg(required = true)]
strings: Vec<String>,
#[arg(required = true, group = "final")]
final_string: Option<String>,
#[arg(long = "final", required = true, group = "final")]
final_: Option<String>,
}
fn main() {
let cli = Cli::parse();
println!("{cli:?}");
}
That said, I would be interested to better understand what end-user equirements are driving a this CLI design. For me, this feels a bit out of the ordinary and could cause user confusion because of that.
There are solutions like
FYI naming this "challenge" and criticizing like this makes it seem like you are more interested in starting an argument than to have a Discussion. Please be respectful in communication. |
Beta Was this translation helpful? Give feedback.
-
Try to use clap for the following:
Command with both this signature:
command <STRINGS...> <FINAL_STRING>
or
command <STRINGS...> --final STRING
Combined this should be:
command <STRINGS...> <<FINAL_STRING>|--final STRING>
That is either a list of arguments and one argument at the end or a list of arguments and an option.
The challenge is to express this with clap to get correct help and error messages and runtime behavior (the
FINAL_STRING
argument is required when--final
is not provided). Obviously no subcommands. I don't think it's possible.I think
clap
is fundamentally too constrained and a bad abstraction. I have thought with it too many times now for commands that go beyond the simple. I think I would be better off with some helpers for parsing and forming help, and moving the actual parsing logic to code.Beta Was this translation helpful? Give feedback.
All reactions