Skip to content

Conversation

@njg7194
Copy link

@njg7194 njg7194 commented Feb 1, 2026

Fixes #4976

Summary

When a default value is an empty string, the help output now displays [default: ""] instead of [default: ], making it clear that the default is an empty string rather than appearing to be missing.

Changes

  • help_template.rs: Added check for empty strings in default value display
  • possible_value.rs: Added check for empty strings in get_visible_quoted_name
  • format.rs: Added check for empty strings in Escape Display impl

Before

Options:
      --text <TEXT>  [default: ]
  -h, --help         Print help

After

Options:
      --text <TEXT>  [default: ""]
  -h, --help         Print help

This is a minimal change that follows the existing pattern of using Rust debug representation for values that need quoting.

Fixes clap-rs#4976

When a default value is an empty string, the help output now displays
`[default: ""]` instead of `[default: ]`, making it clear that
the default is an empty string rather than appearing to be missing.

Changes:
- help_template.rs: Added check for empty strings in default value display
- possible_value.rs: Added check for empty strings in get_visible_quoted_name
- format.rs: Added check for empty strings in Escape Display impl
@epage
Copy link
Member

epage commented Feb 2, 2026

As noted in #4976 (comment) and https://github.com/clap-rs/clap/blob/master/CONTRIBUTING.md#preparing-the-pr, my expectations for this would be

  • Add any tests that are needed to show the current problem
  • Refactor to consolidate to Escape
  • Update Escape with an is_empty check, updating the tests so they continue to pass

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.

Default display for String is awkward, ie [default: ]

2 participants