-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should be possible to make help show --
before TrailingVarArg enabled arg
#888
Comments
The A hack to make the help generation add the arg(Arg::with_name("_foo").long("_foo").takes_value(true).multiple(true).hidden(true)) |
Also, if the usage string is simple, and you don't have many other args (like the example you gave), you could also just add it manually: app.usage("cargo-fuzz run <TARGET> [--] [ARGS]...") The only thing you lose from this is the "context aware" usage strings that happen on error messages. |
@nagisa I took a look at your link, and two things I noticed
let app = App::new("cargo-fuzz")
// Here we lie to clap, saying our binary is actually "cargo" so that our help
// messages and usage strings are all set correctly
.bin_name("cargo")
// Now we add our "fuzz" subcommand
.subcommand(SubCommand::with_name("fuzz")
.version(option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0"))
.about(option_env!("CARGO_PKG_DESCRIPTION").unwrap_or(""))
.setting(AppSettings::SubcommandRequiredElseHelp)
.setting(AppSettings::GlobalVersion)
.subcommand(SubCommand::with_name("init").about("Initialize the fuzz folder"))
.subcommand(SubCommand::with_name("run").about("Run the fuzz target in fuzz/fuzzers")
.setting(AppSettings::TrailingVarArg)
.arg(Arg::with_name("TARGET").required(true)
.help("name of the fuzz target"))
.arg(Arg::with_name("ARGS").multiple(true)
.help("additional libFuzzer arguments passed to the binary"))
)
.subcommand(SubCommand::with_name("add").about("Add a new fuzz target")
.arg(Arg::with_name("TARGET").required(true)))
.subcommand(SubCommand::with_name("list").about("List all fuzz targets"))
)
.get_matches();
If you like the usage string with |
Re dummy I want the binary to work as I'll investigate allow_hyphen_values tonight. |
So I tried In examples, this is what I changed my
Alas, running the help still shows:
I also still need the leading
What is this hack? I tried various ways to construct the
However, not only
Is it even possible to construct something like the following with clap?
(note the non-optional |
Hmm, actually it looks like this doesn't work like I'd thought if you're adding
Aaaah OK now I see exactly what you're trying to do. I was misunderstanding, apologies! That'd be a very easy addition, though. Once I get home tonight I'll wrap it up into #893 and get it out with 2.21.0. With this change the usage string will look like this:
Once I make these changes, the change to your code will be you can remove the |
Alright, I have this basically implemented and ready for a PR. I just need to finish the final test case tonight. |
…st' which means it should be used with `--` syntax and can be accessed early Marking a positional argument `.last(true)` will allow accessing this argument earlier if the `--` syntax is used (i.e. skipping other positional args) and also change the usage string to one of the following: * `$ prog [arg1] [-- <last_arg>]` * `$ prog [arg1] -- <last_arg>` (if the arg marked `.last(true)` is also marked `.required(true)`) Closes #888
This is implemented in #893. Once that merges I'll put out v2.21.0 on crates.io. It'll now be possible to implement:
|
Awesome! |
When
TrailingVarArg
option is enabled, I feel like it should be possible to makehelp
show the--
before this trailing argument:i.e.
or
and not
it shows currently. Code here.
The text was updated successfully, but these errors were encountered: