Replies: 1 comment
-
|
To me, the right solution is your #[derive(Parser, Debug)]
#[command(version, about = "Runs a program with a specific control group")]
struct Cli {
/// Name of the control group.
#[arg()]
cgroup: String,
/// The subcommand to run with its arguments.
#[arg(allow_hyphen_values(true), required = true)]
cmd_args: Vec<OsString>,
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Related: #5305, probably others.
I'm working on a tool cg2exec which takes one positional argument and then forwards all the rest to a subcommand. In the future, it might take flags, but for now it is just the one positional argument. I haven't found a stock Clap setup that has the behavior I'm seeking.
I want the following calls to succeed:
I want the following to fail:
I'm not aware of a Clap configuration with this behavior.
I've tried:
This works for every case except
cg2exec groupname rm -- -myfile.txt, because it seems clap decided to parse--using its own meaning rather than dumping it into theargsvector. It works when the--is the second argument in args, but not the first.I've also tried
This one allows
cg2exec groupname --flag echo hello, which I had wanted to reject. I guess I could add a custom validator to reject the vector if the first argument starts with a hyphen.For now I'm thinking of using
clap_lexmanually (octave-online/cg2tools#3), as suggested in #5305 (reply in thread), since this is not a very complicated CLI, but it would be nice to be able to reduce lines of code and have everything "just work" by using stock clap.Beta Was this translation helpful? Give feedback.
All reactions