GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(argv): four from review, and a build that only breaks for adopters · jdx/usage@54fd029

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • argv/src
    • diagnostic.rs
    • help.rs
  • benches/gate/tests
    • errors.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎argv/src/diagnostic.rs‎

Copy file name to clipboardExpand all lines: argv/src/diagnostic.rs
+29-4Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn flag_named(token: &str) -> &str {
120120
/// The same set the parser would have accepted, which is what makes a suggestion one that works.
121121
fn flags_in_scope<'a, 'c>(
122122
chain: &'c [&'a CommandMeta<'a>],
123-
) -> impl Iterator<Item = &'a crate::spec::FlagMeta<'a>> + use<'a, 'c> {
123+
) -> impl Iterator<Item = &'a crate::spec::FlagMeta<'a>> + 'c {
124124
// The command's own flags, and from each ancestor only what it declared global — the rule
125125
// the parser follows on the way down. The chain and not the tree: an earlier version
126126
// collected globals from every branch it walked through, so a global declared on one command
@@ -569,12 +569,14 @@ pub fn render(
569569
);
570570
}
571571
Error::ConflictingFlags { name, other } => {
572+
// Spelled by `help`, like every other name in this module — and like clap, which
573+
// writes `the argument '--force' cannot be used with '--jobs <JOBS>'`.
572574
let _ = writeln!(
573575
out,
574576
"{} the argument '{}' cannot be used with '{}'",
575577
style.error("error:"),
576-
style.invalid(name),
577-
style.invalid(other)
578+
style.invalid(&shown(here, name)),
579+
style.invalid(&shown(here, other))
578580
);
579581
with_usage = true;
580582
}
@@ -600,7 +602,7 @@ pub fn render(
600602
out,
601603
"{} '{}' can only be given after '{}'",
602604
style.error("error:"),
603-
style.literal(arg.name),
605+
style.literal(&shown(here, arg.name)),
604606
style.literal("--")
605607
);
606608
}
@@ -891,6 +893,29 @@ mod tests {
891893
// `--jobs`.
892894
let message = rendered(&["use"], Error::MissingRequired { name: "jobs" });
893895
assert!(message.contains(" --jobs"), "{message}");
896+
897+
// Every variant, not most of them. These two printed the spec's name while the ones
898+
// directly above and below them did not, so one argument could appear two ways in two
899+
// messages from the same command — and clap writes the dashes here too:
900+
//
901+
// error: the argument '--force' cannot be used with '--jobs <JOBS>'
902+
let message = rendered(
903+
&["use"],
904+
Error::ConflictingFlags {
905+
name: "force",
906+
other: "jobs",
907+
},
908+
);
909+
assert!(
910+
message.contains("the argument '--force' cannot be used with '--jobs'"),
911+
"{message}"
912+
);
913+
914+
let message = rendered(&["use"], Error::ArgRequiresDoubleDash { arg: &SHELLS });
915+
assert!(
916+
message.contains("'[SHELLS]…' can only be given"),
917+
"{message}"
918+
);
894919
}
895920

896921
#[test]
Collapse file

‎argv/src/help.rs‎

Copy file name to clipboardExpand all lines: argv/src/help.rs
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,11 @@ fn annotations(out: &mut String, choices: &[&str], env: Option<&str>, default: &
378378
out.push('\n');
379379
}
380380

381-
/// A flag as the flags section lists it, which includes its negation.
382381
/// How a usage line writes a flag: its first long form, or its short if that is all it has.
383382
///
384-
/// Shared with the diagnostics for the same reason as [`arg_usage`].
383+
/// Shared with the diagnostics for the same reason as [`arg_usage`], and gated with them: under
384+
/// `spec` alone nothing calls it, and a `dead_code` warning is an error in this workspace.
385+
#[cfg(feature = "diagnostics")]
385386
pub(crate) fn flag_spelling(meta: &FlagMeta<'_>) -> String {
386387
meta.flag
387388
.longs
Collapse file

‎benches/gate/tests/errors.rs‎

Copy file name to clipboardExpand all lines: benches/gate/tests/errors.rs
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ fn the_usage_line_is_the_one_the_help_prints() {
117117

118118
#[test]
119119
fn the_suggestion_is_the_one_clap_would_make() {
120-
// Jaro-Winkler above 0.7, which is clap's rule — so the two suggest in the same cases and
121-
// suggest the same thing. Checked against mise's real flags rather than a fixture, because
120+
// Jaro above 0.7, which is clap's rule — plain Jaro, because clap says in its own source
121+
// that `strsim`'s `jaro_winkler` is wrong (GH #4660). So the two suggest in the same cases
122+
// and suggest the same thing. Checked against mise's real flags rather than a fixture, because
122123
// what makes a suggestion good is the size of the set it was chosen from.
123124
let cases = [
124125
(vec!["activate", "zsx"], "a similar value exists: 'zsh'"),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.