Skip to content

Instantly share code, notes, and snippets.

@matklad

matklad/cargo.rs Secret

Created March 6, 2018 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matklad/0d148b1c76c576a0dc0e299962926c30 to your computer and use it in GitHub Desktop.
Save matklad/0d148b1c76c576a0dc0e299962926c30 to your computer and use it in GitHub Desktop.
// that's the code I am using
SubCommand::with_name("bench")
.settings(&[
AppSettings::UnifiedHelpMessage,
AppSettings::DeriveDisplayOrder,
AppSettings::TrailingVarArg,
])
.about("Execute all benchmarks of a local package")
.after_help(help::BENCH)
.arg(
Arg::with_name("BENCHNAME").help(
"If specified, only run benches containing this string in their names"
)
)
.arg(
Arg::with_name("args").help(
"Arguments for the bench binary"
).multiple(true)
)
for `bench foo` I get
matches: ArgMatches {
args: {
"BENCHNAME": MatchedArg {
occurs: 1,
vals: [
"foo"
]
}
},
subcommand: None,
usage: Some(
"USAGE:\n cargo bench [OPTIONS] [--] [ARGS]"
which is what I want
for `bench foo bar` I get
matches: ArgMatches {
args: {
"BENCHNAME": MatchedArg {
occurs: 1,
vals: [
"foo"
]
},
"args": MatchedArg {
occurs: 1,
vals: [
"bar"
]
}
},
subcommand: None,
usage: Some(
"USAGE:\n cargo bench [OPTIONS] [--] [ARGS]"
)
}
Thit is also what I want.
Now, for `cargo bench -- foo bar` I get this again:
matches: ArgMatches {
args: {
"BENCHNAME": MatchedArg {
occurs: 1,
vals: [
"foo"
]
},
"args": MatchedArg {
occurs: 1,
vals: [
"bar"
]
}
},
subcommand: None,
usage: Some(
"USAGE:\n cargo bench [OPTIONS] [--] [ARGS]"
)
}
And what I actually want for `bench -- foo bar` is
matches: ArgMatches {
args: {
"args": MatchedArg {
occurs: 2,
vals: [
"foo", "bar"
]
}
},
subcommand: None,
usage: Some(
"USAGE:\n cargo bench [OPTIONS] [--] [ARGS]"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment