Skip to content

fix(help): render partially optional values with [] in help output#6376

Closed
kimjune01 wants to merge 1 commit into
clap-rs:masterfrom
kimjune01:fix/4847-optional-value-names-help
Closed

fix(help): render partially optional values with [] in help output#6376
kimjune01 wants to merge 1 commit into
clap-rs:masterfrom
kimjune01:fix/4847-optional-value-names-help

Conversation

@kimjune01
Copy link
Copy Markdown

@kimjune01 kimjune01 commented May 13, 2026

Summary

  • Values at index >= num_args.min_values() now render as [name] instead of <name> in help output, correctly indicating they are optional
  • Three branches: positional-optional wraps all (preserves old behavior), option with min_vals==0 wraps none (caller already wraps entire suffix), else min_vals is the cutoff

Fixes #4847

Test plan

  • cargo test: 934 tests across 9 suites, 0 failures
  • Updated option_display3 assertion to match new behavior
  • 3 new tests: option_display_partially_optional_values, option_display_partially_optional_require_equals, option_display_partially_optional_three_values

Hypothesis graph

https://github.com/kimjune01/sweep/blob/master/repo-hypotheses/clap-rs-clap.md

When an option has multiple value names with num_args allowing fewer
values than names (e.g. num_args(1..=2) with value_names(["FOO", "BAR"])),
values beyond the minimum count are now rendered as optional:

    --example <FOO> [BAR]

Previously all values were shown as required regardless of num_args.

Fixes clap-rs#4847
@kimjune01 kimjune01 marked this pull request as draft May 17, 2026 20:09
@kimjune01
Copy link
Copy Markdown
Author

Closing this draft. It isn't backed by a passing regression test on our side, so we'd rather not leave an unvalidated draft open. Thanks for the earlier feedback on #6370.

@kimjune01 kimjune01 closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple optional arguments are displayed incorrectly in help output

1 participant