Skip to content
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

clap suggests hidden subcommands in "similar subcommand" error hints #4853

Open
2 tasks done
yshui opened this issue Apr 21, 2023 · 7 comments
Open
2 tasks done

clap suggests hidden subcommands in "similar subcommand" error hints #4853

yshui opened this issue Apr 21, 2023 · 7 comments
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies S-waiting-on-decision Status: Waiting on a go/no-go before implementing

Comments

@yshui
Copy link

yshui commented Apr 21, 2023

Please complete the following tasks

Rust Version

irrelevant

Clap Version

master

Minimal reproducible code

fn main() {
    clap::Command::new("app")
        .subcommand(clap::Command::new("subcommand").hide(true))
        .get_matches();
}

Steps to reproduce the bug with the above code

cargo run -- su

Actual Behaviour

error: unrecognized subcommand 'su'

  tip: a similar subcommand exists: 'subcommand'

Expected Behaviour

nothing is suggested.

Additional Context

No response

Debug Output

No response

@yshui yshui added the C-bug Category: Updating dependencies label Apr 21, 2023
@yshui
Copy link
Author

yshui commented Apr 21, 2023

Fix in #4852

@epage
Copy link
Member

epage commented Apr 21, 2023

Can you give your use case as to why you expect hidden subcommands to be not suggested?

The exact semantics of hide come up from time to time. For example, we suggest hidden subcommands and arguments in completions (#1335). In the new completion system, the proposal is to not suggest completing hidden items by default but to instead complete them if it looks like the user is intending to use the hidden item (#3951).

This latter case sounds similar to suggestions in errors which runs counter to this issue / #4852 which is why this merits further discussion.

@yshui
Copy link
Author

yshui commented Apr 21, 2023

so the tool I am working on has commands that is not intended to be run manually, at all. they are only intended to be invoked internally by the tool itself.

i am ok with only suggesting them when the user do intend to use them, but i don't see how you can reliably detect user intentions.

i found this to be a problem because clap suggested things like __subcommand when i typed sub.

@epage epage added S-waiting-on-decision Status: Waiting on a go/no-go before implementing A-help Area: documentation, including docs.rs, readme, examples, etc... labels Apr 21, 2023
@yshui
Copy link
Author

yshui commented Apr 21, 2023

maybe there can be two levels of hidden-ness? like, hidden and hidden hidden

@weihanglo
Copy link

With #5075, we have UnknownArgumentValueParser to guide users to use the correct flag. If clap provides a way to stop typo-suggesting a flag, it would be perfect!

Carreau added a commit to Carreau/clap that referenced this issue Aug 28, 2023
As pointed out in clap-rs#4853, it might be useful to mark arguments to not be
considered by the suggestions feature.

In particular with the introduction of UnknownArgumentValueParser in clap-rs#5075,
one might want explicitly handle some common confusion (say handle
`--silent` and print `tip: did you mean --quiet`), but not have those in
the suggestion engine. I'm guessing one might want to have an `arg` be visible
but not in suggestion for deprecated flags as well.

I'm trying to do so by adding a `.didyoumena(false)`, that will mark the
argument as to not be considered by suggestion.

There is also some mention of completion of hidden command in clap-rs#4853,
that might be relevant as well.

--

I'm not too familiar with clap internals, and fairly new to rust,
but in particular :

 - I've tried to implement that only for args - I guess we will need to
   extend to subcommands if this goes further
 - I'm not happy with the setting negations nor the naming
   `didyoumean`/`ExcludeDidYouMean`
 - I'm not super happy about the iteration over MKeyMap keys and items.
Carreau added a commit to Carreau/clap that referenced this issue Aug 28, 2023
As pointed out in clap-rs#4853, it might be useful to mark arguments to not be
considered by the suggestions feature.

In particular with the introduction of UnknownArgumentValueParser in clap-rs#5075,
one might want explicitly handle some common confusion (say handle
`--silent` and print `tip: did you mean --quiet`), but not have those in
the suggestion engine. I'm guessing one might want to have an `arg` be visible
but not in suggestion for deprecated flags as well.

I'm trying to do so by adding a `.didyoumena(false)`, that will mark the
argument as to not be considered by suggestion.

There is also some mention of completion of hidden command in clap-rs#4853,
that might be relevant as well.

--

I'm not too familiar with clap internals, and fairly new to rust,
but in particular :

 - I've tried to implement that only for args - I guess we will need to
   extend to subcommands if this goes further
 - I'm not happy with the setting negations nor the naming
   `didyoumean`/`ExcludeDidYouMean`
 - I'm not super happy about the iteration over MKeyMap keys and items.
@Carreau
Copy link

Carreau commented Aug 28, 2023

I was curious and tried to find a way to do so in #5097.

It adds .didyoumean(false) that filter out arguments from the suggestion logic. In combination with .hide(...) I think that would create what @weihanglo wants and we can extends for subcommands for @yshui.

Anyway just a suggestion instead of fighting for wether or not hide(...) should suggest or not.

@epage
Copy link
Member

epage commented Aug 28, 2023

I think that would create what @weihanglo wants

There was more discussion in rust-lang/cargo#11702 and it is unclear what we want the behavior to be in that case.

Anyway just a suggestion instead of fighting for wether or not hide(...) should suggest or not.

Except this shifts the discussion to whether this part of the API pulls enough weight to justify itself. We've been focusing recently on shrinking clap, in binary size, in compile time, and in API size. The bigger the API is, the harder it is to find anything, making it less likely people will use any of the features in the API, lowering the value gained by having each piece of the API.

@epage epage changed the title clap suggests hidden subcommands clap suggests hidden subcommands in errors Jan 15, 2024
@epage epage changed the title clap suggests hidden subcommands in errors clap suggests hidden subcommands in "similar subcommand" error hints Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-bug Category: Updating dependencies S-waiting-on-decision Status: Waiting on a go/no-go before implementing
Projects
None yet
Development

No branches or pull requests

4 participants