Clap/structop: A way to not require `- -`?

#1

I’m trying to build a command that will call git in a given directory, passing all the arguments.

However this fails:

cargo crev db git commit -a

and I have to use:

cargo crev db git -- commit -a

to make structopt/clap know that -a is not an argument to my command.

My git sub-commands looks like this:

#[derive(Debug, StructOpt, Clone)]
pub struct Git {
    /// Arguments to git command
    #[structopt(parse(from_os_str))]
    pub args: Vec<OsString>,
}

Any way to make that -- not be required?

#2

I know for clap there’s https://docs.rs/clap/2.32.0/clap/enum.AppSettings.html#variant.TrailingVarArg to do this.

From structop's raw example, it seems like this could worK:

#[derive(Debug, StructOpt, Clone)]
#[structopt(raw(setting = "structopt::clap::AppSettings::TrailingVarArg"))]
pub struct Git {
    /// Arguments to git command
    #[structopt(parse(from_os_str))]
    pub args: Vec<OsString>,
}
1 Like
#3

Thank you. I’ll try it out.

#4

I actually had to do it one level higher:

    /// Run raw git commands in the local proof repository
    #[structopt(name = "git")]
    #[structopt(raw(setting = "structopt::clap::AppSettings::TrailingVarArg"))]
    Git(Git),

But it works! Thank you!

1 Like