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
Don't suggest --
in errors if it isn't relevant
#2766
Comments
@ldm0 Can we skip that if the subcommand we are parsing doesn't have any args with multiple values? |
--
in errors if it isn't relevant
Two extra points:
|
@matklad could you expand further on those points so that we better balance the different needs when coming up with a solution. For example
I'm assuming the problem is: "When running a subcommand, I assumed some flags were global and put them after the subcommand and it failed, producing this message which doesn't apply to my situation" If we made the message conditioned on there being positional arguments, that'll make it so we never show it when it isn't applicable but it can still show up in the workflow you mentioned if the subcommand has positional arguments. This is one of the points I'm trying to understand since by the direction and strength of your comments it sounds like that wouldn't be acceptable but I want to understand why.
What was it that was so frustrating with it? If you ended up going down the wrong path, what was it about the message that you went that way? I'm trying to understand what is so frustrating about this when to me it clearly articulates when the suggestion is relevant. This doesn't mean that you wrong but that you have a different perspective that we need to incorporate in handling this. |
Yeah. And, in particular, this seems to be a very frequent problem, rather than an obscure edge case. More generally, it seems to me that more or less any mistake in the args leads to "If you tried to supply ..." message (although often with a more relevant suggestion as well), but the probability that I actually indeed meant to pass
Several things:
More generally, features which make life more complicated with comparison to a hypothetical where such feature did't exist create a feeling of frustration. |
It had a condition on the suggestion. What was unclear about the condition that you thought it applied (since you were trying to pass a flag instead of a value)? Or is it a case of "scan and just do what it says", missing the condition? |
I can understand in this case. I have personally been in the same situation as #1284 many times and haven't even considered using |
Exactly this: I am a user in a hurry, whose mind is occupied by an unrelated problem. I don't have mental space to carefully consider if-then-else clauses. If a tool suggests some solution, my assumption is that that indeed is the most probable fix.
Exactly: there are some specific contexts where
That's sort of Bayes' rule, baseline probabilities matter. There's a bunch of ways we can make this more specific:
|
For now, #4380 limits the
Something I've also been considering for both clap and cargo is following the rustc diagnostic guidelines of not suggesting things to users but informing users what exist. EDIT: To be clear, I'm leaving this open to encourage further discussion on the overall direction |
From https://rustc-dev-guide.rust-lang.org/diagnostics.html#suggestion-style-guide > Suggestions should not be a question. In particular, language like > "did you mean" should be avoided. Sometimes, it's unclear why a > particular suggestion is being made. In these cases, it's better to be > upfront about what the suggestion is. > > The message may contain further instruction such as "to do xyz, use" > or "to do xyz, use abc". Inspired by clap-rs#2766
I've created #4385 to tweak the wording of the suggestions. It could probably use some more work and I'm hesitant in doing a change like this in a patch release as people might design some of their own CLI to match clap and changing it could provide a degraded experience, so we might want to call attention to this by saving it for a minor release. |
v4.0.15 is released with #4380. |
#4380 (or changes since then since that was quite some time ago) doesn't help with subcommands: > sshagmux lis
error: unrecognized subcommand 'lis'
tip: a similar subcommand exists: 'list'
tip: to pass 'lis' as a value, use 'sshagmux -- lis'
Usage: sshagmux <COMMAND>
For more information, try '--help'. There is nowhere for "values" to go, and in fact trying to use this form emits the exact same error message > sshagmux -- lis
error: unrecognized subcommand 'lis'
tip: a similar subcommand exists: 'list'
tip: to pass 'lis' as a value, use 'sshagmux -- lis'
Usage: sshagmux <COMMAND>
For more information, try '--help'. |
That is fixed in v4.3.18 by #5033 |
Please complete the following tasks
Clap Version
3.0.0-beta.4
Describe your use case
Hi.
Assuming I have an
args.rs
file:and a
main.rs
:if I call the executable like this (passing an invalid flag):
it returns this message:
Describe the solution you'd like
It would be nice any global configuration in Clap to avoid suggestions like
-- -x
. The message would be like this, which is much clear for the user (since the application contains only two optional flags):or:
or even:
Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: