Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions argv/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,8 @@ fn flag_usage_masked(meta: &FlagMeta<'_>, show: &Shown) -> String {
// spec does not.
//
// Judged on the forms this page is *showing*. mise's root has a global `-E --env`; a
// descendant that claims `--env` leaves `-E` inherited, and `-E <ENV>` alone gives a
// reader nothing to connect it to the `--env` they saw elsewhere. `env: -E <ENV>` does.
// descendant that claims `--env` leaves `-E` inherited, and `-E <ENV>` alone gives a
// reader nothing to connect it to the `--env` they saw elsewhere. `env: -E <ENV>` does.
let long = show.long;
let short = show.short.as_ref();
let implied = long.or_else(|| short.map(|_| ""));
Expand Down Expand Up @@ -919,11 +919,6 @@ fn flag_usage_masked(meta: &FlagMeta<'_>, show: &Shown) -> String {
let _ = write!(out, "--{long}");
}

// A repeatable flag, which is the spec's `var=#true` — not one occurrence taking several
// values, which is the value's own business below.
if meta.repeatable {
out.push('…');
}
if flag.takes_value {
// Angled where the value must be given, squared where it need not — the same brackets
// an argument uses, and for the same reason. pitchfork's `--bump` is the fleet's case.
Expand Down
44 changes: 44 additions & 0 deletions conformance/tests/flag_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! there is a long form to line up with. `-j <JOBS>` has none, so it does not pad; that is
//! clap's behaviour and not an oversight in it.

use usage::docs::markdown::MarkdownRenderer;
use usage_argv::help;
use usage_derive::Cli;

Expand All @@ -39,6 +40,49 @@ struct Ex {
describe: bool,
}

#[derive(Cli)]
#[usage(bin = "repeat")]
#[allow(dead_code)]
struct Repeatable {
/// A repeatable value
#[usage(short = 'A', long, value_name = "NAME")]
allow: Vec<String>,
/// Repeatable verbosity
#[usage(long, count)]
verbose: u8,
}

#[test]
fn repeatable_flags_have_ordinary_spellings_in_every_rendered_format() {
for long in [false, true] {
let compiled =
help::render(Repeatable::spec(), Repeatable::spec().root.cmd, long).expect("a page");
assert!(
compiled.contains("-A, --allow <NAME>"),
"long={long}: {compiled}"
);
assert!(compiled.contains("--verbose"), "long={long}: {compiled}");
assert!(!compiled.contains('…'), "long={long}: {compiled}");

let spec: usage::Spec = Repeatable::to_kdl().parse().expect("generated spec");
let allow = spec
.cmd
.flags
.iter()
.find(|flag| flag.name == "allow")
.expect("generated spec should contain allow");
assert!(allow.var, "allow must remain repeatable in generated spec");
let reference = usage::docs::cli::render_help(&spec, &spec.cmd, long);
assert_eq!(reference, compiled);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

let markdown = MarkdownRenderer::new(spec.clone())
.render_cmd(&spec.cmd)
.expect("markdown page");
assert!(markdown.contains("-A --allow <NAME>"), "{markdown}");
assert!(!markdown.contains('…'), "{markdown}");
}
}

fn page(long: bool) -> String {
help::render(Ex::spec(), Ex::spec().root.cmd, long).expect("a page")
}
Expand Down
4 changes: 2 additions & 2 deletions corpus/render/01-flag-values.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
},
{
"id": "flag-repeatable-with-optional-value",
"doc": "A repeatable flag's own ellipsis follows the spellings, before the value — so a repeatable flag taking an optional value shows both.",
"doc": "A repeatable flag uses its ordinary spelling in output; repeatability remains structural metadata rather than a presentation suffix.",
"spec": "name \"ex\"\nbin \"ex\"\nflag \"--jobs [n]\" var=#true required=#true help=\"How many\"\n",
"expect": {
"usage": "ex <--jobs [n]>"
"usage": "ex <--jobs [n]>"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/reference/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
},
{
"name": "env",
"usage": "-e --env <ENV>",
"usage": "-e --env <ENV>",
"help": "Environment to explain against, as KEY=VALUE, repeatable",
"help_long": "Environment to explain against, as KEY=VALUE, repeatable\n\nGiven at all, these are the *whole* environment: an explanation pasted into a bug report has to mean the same thing on the machine that reads it. Omitted, the process environment is used, which is what an execution would see.",
"help_first_line": "Environment to explain against, as KEY=VALUE, repeatable",
Expand Down Expand Up @@ -1434,7 +1434,7 @@
},
{
"name": "template",
"usage": "--template <TEMPLATE>",
"usage": "--template <TEMPLATE>",
"help": "Override a Tera template with NAME=PATH",
"help_first_line": "Override a Tera template with NAME=PATH",
"short": [],
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/reference/explain.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ command line does not parse: the report succeeded, and that is the case worth a
**Default:** `text`

- **`--view <VIEW>`** — A spec-declared executable view to explain
- **`-e --env <ENV>`** — Environment to explain against, as KEY=VALUE, repeatable
- **`-e --env <ENV>`** — Environment to explain against, as KEY=VALUE, repeatable

Given at all, these are the _whole_ environment: an explanation pasted into a bug report has to mean the same thing on the machine that reads it. Omitted, the process environment is used, which is what an execution would see.

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/reference/generate/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Generate markdown documentation from usage specs

- **`--replace-pre-with-code-fences`** — Replace `<pre>` tags with markdown code fences
- **`--url-prefix <URL_PREFIX>`** — Prefix to add to all URLs
- **`--template <TEMPLATE>`** — Override a Tera template with NAME=PATH
- **`--template <TEMPLATE>`** — Override a Tera template with NAME=PATH
- **`-h --help`** — Print help
Loading