-
-
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
Ability to show possible value help in --help #3312
Comments
@ModProg as the person who implemented this, I assume you use this and would have thoughts / perspective on whether we should show this in If we do show the |
Yeah, that makes sense I'd say, should probably be configurable, but the current behavior of only showing the help in the completions seams a bit strange in retrospect. Should have been in the help as well, is my gut reaction. |
But I'm not sure on what would be the best way of displaying this:
|
Yes, I was thinking a bulleted list would probably be how we show this. iirc I brought up showing them this way in the PR for The next question is if this would be considered a "breaking change", meaning that people have crafted their CLIs around the current behavior and it would egregiously impact the UI to change this without a more explicit acknowledgement of breaking behavior. For builder users, it depends on if they've discovered and started to use this new feature while manually documenting the value meanings. For derive users, the situation is different because we are picking up the doc comments and users are most likely not using |
Well not if it was off by default, but I see your point. As I would like this to be the default behaviour as that seams like the natural effect of the This could be done in a two step prosses I guess (first opt in, then opt out)? Not sure, what the best way is. |
My preference is to avoid configuration long term. Clap's API is so bloated, it makes it difficult to know whats there or not. If we can make a policy that can reasonably apply to nearly all programs, we have issues like #2914 for the rest. If we are concerned about the transition, we could use either a manifest feature flag or a setting as we transition to the new behavior. maybe we even toggle it for the major release after that but the following would see the option removed ideally. |
yeah, I think this is the expected behavior, I just did not think about it when I first started looking into this. IMO as the doc comments are relevant on all other clap derives, it is reasonable to have them just appear in the help message. We can put a warning in the change log (tho I understand that most people won't look there). |
Yeah, another option I was considering was waiting for 3.1 and having a "Backwards Compatibility" section in the changelog, like Rust. |
Sounds reasonable, if there are more features like this that are kind of unstable/breaking changes we could put them behind a feature flag until 3.1 or just have an off by default setting till then. |
Some thoughts as the requester: I hadn't thought of the documentation not being suitable to be shown, but I was thinking that it might be too long. However, long possible value lists are likely to be Some command line tools offer dedicated options to list possible values when there are lots of them (to name a couple of examples I've seen, lists of compatible hardware, or file formats/codecs); it might be interesting to offer help implementing that, but on the other hand it's easy to do and might want customization. As to specifics of formatting, here is the result of what I picked for my application-specific implementation:
I don't entirely recommend exactly this: the bullets are a bit noisy, but I added them because from the outside I can't get clap to indented-wrap the entries for visual clarity (that is, indent the wrapped lines " I do think the columnar alignment is a good idea given enough available width. Here's my implementation: static GRAPHICS_HELP: Lazy<String> = Lazy::new(|| {
let pv_iter = GraphicsType::value_variants()
.iter()
.filter_map(|v| v.to_possible_value());
let max_width = pv_iter
.clone()
.filter_map(|pv| pv.get_visible_name())
.map(str::len)
.max()
.unwrap_or(0);
let mut text = String::from("Graphics/UI mode; one of the following keywords:\n");
for pv in pv_iter {
// Note: There's a final newline so that clap's default value text is put on a new line.
writeln!(
text,
"• {:max_width$} — {}",
pv.get_name(),
pv.get_help().unwrap()
)
.unwrap();
}
text
}); (This isn't quite fully general: it doesn't handle hidden items or ones without documentation, which didn't matter since it's hardcoded to this one enum.) |
In case it wasn't clear, the concern is more with people who have already written rustdoc comments who might be surprised to see those starting to show up in the help
Yes, that is a concern. One thing that helps is that clap has distinct
A good example of this (though its more dynamic) $ cargo test --test
error: "--test" takes one argument.
Available tests:
builder
derive
derive_ui
examples
macros
yaml I feel like we could model our errors off of this. Right now, we don't use possible values in the errors: $ git-stack --color
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `/home/epage/src/personal/git-stack/target/debug/git-stack --color`
error: The argument '--color <WHEN>' requires a value but none was supplied
USAGE:
git-stack [OPTIONS]
For more information try --help
$ git-stack --color lklk
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `/home/epage/src/personal/git-stack/target/debug/git-stack --color lklk`
error: Invalid value for '--color <WHEN>': Unknown color choice 'lklk'
For more information try --help
If we only do this for It is a good point that we should indent any wrapped lines for the bullets. As for the exact bullet symbol, we can determine that later. Using coloring will also help. |
Like was said in clap-rs#2435, this is what people would expect. While we should note this in a compatibility section in the changelog, I do not consider this a breaking change since we should be free to adjust the help output as needed. We are cautious when people might build up their own content around it (like clap-rs#3312) but apps should already handle this with `--help` so this shouldn't be a major change. We aren't offering a way for people to disable this, assuming people won't need to. Longer term, we are looking at support "Actions" (clap-rs#3405) and expect those to help customize the flags. We'll need something similar for the `help` subcommand. Fixes clap-rs#3440
Like was said in clap-rs#2435, this is what people would expect. While we should note this in a compatibility section in the changelog, I do not consider this a breaking change since we should be free to adjust the help output as needed. We are cautious when people might build up their own content around it (like clap-rs#3312) but apps should already handle this with `--help` so this shouldn't be a major change. We aren't offering a way for people to disable this, assuming people won't need to. Longer term, we are looking at support "Actions" (clap-rs#3405) and expect those to help customize the flags. We'll need something similar for the `help` subcommand. Fixes clap-rs#3440
Just ran into this exact issue. I now needed to specify separate help messages for long and short, because I wanted to have
in long help. I thought about adding an aditional If you have a plan on how this should be implemented @epage I would go ahead and look into it. |
I've not done this yet because I keep oscillating on whether this would be considered a breaking change or not, with the biggest concern being for derive users. What we can do is add a Steps
Rough template
(of course, willing to hear other ideas on any of this) |
Makes sense, if I see correctly, the new possible value display would need to go here: Line 436 in bc2be89
Should extract the logic whether to use the long possible value help in a helper function so that hiding the old help and showing the new help use the same code? |
Yes, we'll have possible-value printing in two different places, depending on if its long or short. That is the place for doing it for long. The current place we print possible values is exclusively for the |
After some more investigation, a few questions:
|
Most likely not but unsure why this is relevant. We should be basing what we do off of
Ideally |
It is relevant because it means that the indenting logic needs to support it. |
The possible value name will not be wrapped (when using |
This is now available in v3.1.4 behind the |
Please complete the following tasks
Clap Version
3.0.8
Describe your use case
I have options which take one of several possible values and which would benefit from explaining what each of the values do. I am currently putting this text in the option's
help
but I could easily forget to update that, and a list inside the help text doesn't wrap nicely.Describe the solution you'd like
A setting which causes each possible value's PossibleValue::help to be displayed as part of the help for the option (instead of just listing the possible values without any help, which is the current default behavior).
(Perhaps it should not be an additional setting, but be the default behavior whenever the possible values have help strings. I don't know what typical use cases look like to say whether this would be undesirable verbosity.)
Alternatives, if applicable
I currently have hardcoded option help text listing the values, which is what I was hoping
PossibleValue::help
would replace before I tried it and found that it didn't. Another alternative would be to implement this using existing facilities by iterating over the possible values and building a help string. However, clap could do this better than the application can, by formatting the list of values and help in a text-wrapping-aware way.Additional Context
No response
The text was updated successfully, but these errors were encountered: