Skip to content

When displaying default values do not display [] when value is null #2582

Closed

Description

@blowdart

v2.0.0-beta5.25306.1

I have some default values that can be sourced from environment variables if they're present.

For example,

        var passwordOption = new Option<string?>("--password". "-p", "/p")
        {
            Description = "The password to use.",
            DefaultValueFactory = defaultValue =>
            {
                if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("_Password")))
                {
                    return null;
                }

                return Environment.GetEnvironmentVariable("_Password");
            }
        };

Currently the help text would display

-p, --password          The password to use. []

It would, to my mind, be cleaner if, when the DefaultValueFactory returns null that nothing is displayed as the default, because in this case there is no default.

e.g.

-p, --password          The password to use.

Activity

  1. added
    bug
    on Jun 20, 2025
  2. added this to the 2.0.0-beta6 milestone on Jun 20, 2025
  3. changed the title [-]When displaying default values do not disable when value is null[/-] [+]When displaying default values do not display [] when value is null[/+] on Jun 21, 2025
  4. barrygiles commented on Jun 23, 2025

    @barrygiles

    +1 for this

    It also affects required options, in that the system thinks the option has been set (with null), whereas practically speaking it hasn't.

  5. self-assigned this
    on Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-Helpbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions