Let's say I'm writing a command-line program called foo
, using clap as the arguments parser:
#[derive(Debug, Parser)]
struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
Run {
executable: OsString,
args: Vec<OsString>,
},
}
One of the things it's supposed to do is run other command-line programs. For example, to tell foo
to run the executable bar
, the user would run:
foo run bar
If the user tries to pass flags for bar
:
foo run bar --baz
...I would like them to be captured as raw arguments so that they can be passed directly to bar
like so:
Cli {
command: Run {
executable: "bar",
args: [
"--baz",
],
},
}
However instead of capturing it as a raw argument, clap parses it as a flag for foo
to handle.
Is there any way to tell clap to ignore any flags it sees after a certain point?
I'm aware that the user could tell clap to stop parsing subsequent arguments as flags like so:
foo run -- bar --baz
I'd like to avoid this workaround if possible, since it's more verbose than necessary and it's somewhat counterintuitive from a user perspective. Usually you put in a --
to avoid having args processed as flags, not the other way around.