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 — feat(help): list the flags a command inherits (#913) · jdx/usage@fa7c0a6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • argv/src
    • complete.rs
    • help.rs
  • benches/gate/tests
    • help.rs
  • conformance/tests
    • global_flags.rs
    • help_request.rs
    • metadata.rs
  • lib/src/docs/cli
    • mod.rs
    • templates
      • spec_template_long.tera
      • spec_template_short.tera
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎argv/src/complete.rs‎

Copy file name to clipboardExpand all lines: argv/src/complete.rs
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ pub fn for_name<'a>(
198198
// Tree order last, and only as a fallback: two sibling commands may take a `tool` and mean
199199
// different things by it, and the one the line reached is the one being asked about.
200200
let reached = walk(spec.root.cmd, ctx.command_words_start());
201-
let reached_meta = crate::help::find(spec, reached.cmd).map(|(_, meta)| meta);
201+
let reached_meta =
202+
crate::help::find(spec, reached.cmd).and_then(|(_, chain)| chain.last().copied());
202203
let owner = if on(spec.root, name).is_some() {
203204
spec.root
204205
} else if let Some(meta) = reached_meta.filter(|meta| on(meta, name).is_some()) {
@@ -407,7 +408,7 @@ fn files_for(name: &str) -> Option<Files> {
407408
/// for a word nothing is known about, and the `run=` completions a spec can declare.
408409
pub fn complete<'a>(spec: &'a Spec<'a>, split: &Split) -> Completions<'a> {
409410
let position = walk(spec.root.cmd, split.argv());
410-
let meta = crate::help::find(spec, position.cmd).map(|(_, meta)| meta);
411+
let meta = crate::help::find(spec, position.cmd).and_then(|(_, chain)| chain.last().copied());
411412
let token = split.prefix.as_str();
412413
let candidates = candidates(spec, split);
413414

@@ -476,7 +477,7 @@ pub fn complete<'a>(spec: &'a Spec<'a>, split: &Split) -> Completions<'a> {
476477
/// Just the candidates this CLI knows about, without the question of paths.
477478
pub fn candidates<'a>(spec: &'a Spec<'a>, split: &Split) -> Vec<Candidate<'a>> {
478479
let position = walk(spec.root.cmd, split.argv());
479-
let meta = crate::help::find(spec, position.cmd).map(|(_, meta)| meta);
480+
let meta = crate::help::find(spec, position.cmd).and_then(|(_, chain)| chain.last().copied());
480481
let token = split.prefix.as_str();
481482

482483
let mut out = if position.flags_possible && token == "-" {
Collapse file

‎argv/src/help.rs‎

Copy file name to clipboardExpand all lines: argv/src/help.rs
+249-43Lines changed: 249 additions & 43 deletions
Large diffs are not rendered by default.
Collapse file

‎benches/gate/tests/help.rs‎

Copy file name to clipboardExpand all lines: benches/gate/tests/help.rs
+20-13Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ fn mise_spec() -> LibSpec {
2323
/// Every command in the tree, as (path, metadata) — the path being what a user types.
2424
fn walk<'a>(
2525
path: Vec<&'a str>,
26+
chain: Vec<&'a CommandMeta<'a>>,
2627
meta: &'a CommandMeta<'a>,
27-
out: &mut Vec<(Vec<&'a str>, &'a CommandMeta<'a>)>,
28+
out: &mut Vec<(Vec<&'a str>, Vec<&'a CommandMeta<'a>>)>,
2829
) {
29-
out.push((path.clone(), meta));
30+
// The chain and not just the command: a page lists what it inherits, which only the
31+
// ancestors know.
32+
let mut chain = chain;
33+
chain.push(meta);
34+
out.push((path.clone(), chain.clone()));
3035
for sub in meta.subcommands {
3136
// Aliases live in the parse table beside the canonical name; help names the command.
3237
let mut child = path.clone();
3338
child.push(sub.cmd.name);
34-
walk(child, sub, out);
39+
walk(child, chain.clone(), sub, out);
3540
}
3641
}
3742

@@ -50,15 +55,17 @@ fn every_usage_line_matches_the_reference() {
5055
let root = shadow_mise::Cli::spec().root;
5156

5257
let mut commands = Vec::new();
53-
walk(vec!["mise"], root, &mut commands);
58+
walk(vec!["mise"], Vec::new(), root, &mut commands);
5459
assert!(
5560
commands.len() > 200,
5661
"the shadow should cover mise's whole tree, found {}",
5762
commands.len()
5863
);
5964

6065
let mut differences = Vec::new();
61-
for (path, meta) in &commands {
66+
for (path, chain) in &commands {
67+
// The usage line is about the command itself; the chain is for what it inherits.
68+
let meta = chain.last().expect("a command");
6269
let ours = usage_line(path, meta);
6370
// usage-lib's `usage()` omits the binary and starts at the command path, so the
6471
// comparison puts it back — the same string the template writes after `Usage: `.
@@ -129,7 +136,7 @@ fn every_short_help_matches_the_reference() {
129136
let root = shadow_mise::Cli::spec();
130137

131138
let mut commands = Vec::new();
132-
walk(vec!["mise"], root.root, &mut commands);
139+
walk(vec!["mise"], Vec::new(), root.root, &mut commands);
133140

134141
let mut differences = Vec::new();
135142
for (path, meta) in &commands {
@@ -173,7 +180,7 @@ fn every_long_help_matches_the_reference() {
173180
let root = shadow_mise::Cli::spec();
174181

175182
let mut commands = Vec::new();
176-
walk(vec!["mise"], root.root, &mut commands);
183+
walk(vec!["mise"], Vec::new(), root.root, &mut commands);
177184

178185
let mut differences = Vec::new();
179186
for (path, meta) in &commands {
@@ -276,12 +283,12 @@ fn the_text_around_a_page_is_rendered_where_the_reference_puts_it() {
276283
};
277284

278285
assert_eq!(
279-
short_help(&SPEC, &["ex", "go"], &GO_META),
286+
short_help(&SPEC, &["ex", "go"], &[&GO_META]),
280287
usage::docs::cli::render_help(&spec, go, false),
281288
"short form"
282289
);
283290
assert_eq!(
284-
long_help(&SPEC, &["ex", "go"], &GO_META),
291+
long_help(&SPEC, &["ex", "go"], &[&GO_META]),
285292
usage::docs::cli::render_help(&spec, go, true),
286293
"long form"
287294
);
@@ -330,9 +337,9 @@ fn a_spec_can_surround_every_page_at_once() {
330337

331338
for long in [false, true] {
332339
let ours = if long {
333-
long_help(&SPEC, &["ex", "go"], &GO_META)
340+
long_help(&SPEC, &["ex", "go"], &[&GO_META])
334341
} else {
335-
short_help(&SPEC, &["ex", "go"], &GO_META)
342+
short_help(&SPEC, &["ex", "go"], &[&GO_META])
336343
};
337344
assert_eq!(
338345
ours,
@@ -442,9 +449,9 @@ fn a_specs_examples_reach_a_page_that_has_none() {
442449
let cmd = spec.cmd.subcommands.get(name).expect("in the spec");
443450
for long in [false, true] {
444451
let ours = if long {
445-
long_help(&SPEC, &["ex", name], meta)
452+
long_help(&SPEC, &["ex", name], &[meta])
446453
} else {
447-
short_help(&SPEC, &["ex", name], meta)
454+
short_help(&SPEC, &["ex", name], &[meta])
448455
};
449456
assert_eq!(
450457
ours,

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.