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

Singular used even when multiple suggestions exist note: subcommand 'foo', 'bar' exist #4666

Closed
2 tasks done
corneliusroemer opened this issue Jan 23, 2023 · 0 comments · Fixed by #4667
Closed
2 tasks done
Labels
C-bug Category: Updating dependencies

Comments

@corneliusroemer
Copy link
Contributor

corneliusroemer commented Jan 23, 2023

Please complete the following tasks

Rust Version

1.66.1

Clap Version

master

Minimal reproducible code

There already exists a test that expects the wrong grammar (intentionally?):

note: subcommand 'test', 'temp' exist
directly

This can be confusing, as the user could think that usage of singular has meaning and starts to think about why singular is used.

Steps to reproduce the bug with the above code

NA

Actual Behaviour

note: subcommand 'test', 'temp' exists

Expected Behaviour

note: subcommands 'test', 'temp' exist

-> Add a suffix -s subcommand and get rid of exists suffix -s

Additional Context

Possible fix could be in

clap/src/error/format.rs

Lines 70 to 85 in 90c042e

if let Some(valid) = error.get(ContextKind::SuggestedSubcommand) {
styled.none("\n");
if !suggested {
styled.none("\n");
suggested = true;
}
did_you_mean(&mut styled, "subcommand", valid);
}
if let Some(valid) = error.get(ContextKind::SuggestedArg) {
styled.none("\n");
if !suggested {
styled.none("\n");
suggested = true;
}
did_you_mean(&mut styled, "argument", valid);
}

Though this would require a bit of extra code = increased complexity.

Interestingly, the plural/singular of the exist/exists part is correctly implemented already in

clap/src/error/format.rs

Lines 440 to 460 in 90c042e

styled.none(context);
styled.none(" ");
for (i, valid) in valid.iter().enumerate() {
if i != 0 {
styled.none(", ");
}
styled.none("'");
styled.good(valid);
styled.none("'");
}
if valid.len() == 1 {
styled.none(" exists");
} else {
styled.none(" exist");
}
}
}
fn escape(s: impl AsRef<str>) -> String {
let s = s.as_ref();
if s.contains(char::is_whitespace) {

Debug Output

No response

@corneliusroemer corneliusroemer added the C-bug Category: Updating dependencies label Jan 23, 2023
@corneliusroemer corneliusroemer changed the title Singular used even when multiple suggestions exist note: subcommand 'foo', 'bar' exist Singular used even when multiple suggestions exist note: subcommand 'foo', 'bar' exists Jan 23, 2023
@corneliusroemer corneliusroemer changed the title Singular used even when multiple suggestions exist note: subcommand 'foo', 'bar' exists Singular used even when multiple suggestions exist note: subcommand 'foo', 'bar' exist Jan 23, 2023
corneliusroemer added a commit to corneliusroemer/clap that referenced this issue Jan 23, 2023
corneliusroemer added a commit to corneliusroemer/clap that referenced this issue Jan 23, 2023
Old: `note: subcommand 'test', 'temp' exist`
New: `note: subcommands 'test', 'temp' exist`
Fixes clap-rs#4666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant