Skip to content

--help output lacks "[default: true]" if Option<bool> has DefaultValueFactory returning true #2738

@DrusTheAxe

Description

@DrusTheAxe

System.CommandLine version 2.0.0-rc.2.25502.107

Define an Option with a DefaultValueFactory for some non-default value and --help outputs the option, description and default value UNLESS the type is bool then the default is omitted even though DefaultValueFactory returns true

...
new Option<int>("--bool")
{
    Description = "Bool value"
},
new Option<int>("--bool-default")
{
    Description = "Bool value with default",
    DefaultValueFactory = result => { return true; }
},
new Option<int>("--int")
{
    Description = "Int value"
},
new Option<int>("--int-default")
{
    Description = "Int value with default",
    DefaultValueFactory = result => { return 123; }
},
new Option<string>("--string")
{
    Description = "String value"
},
new Option<string>("--string-default")
{
    Description = "String value with default",
    DefaultValueFactory = result => { return "my.default.value"; }
},
...

Run foo.exe --help and the output's

...
  --bool                                                        Bool value
  --bool-default                                                Bool value with default
  --int <int>                                                   Int value
  --int-default <int-default>                                   Int value with default [default: 123]
  --string <string>                                             String value
  --string-default <string-default>                             String value with default [default: my.default.value]
...

The 2nd line is wrong it should end with "[default: true]" e.g.

--bool-default                                                Bool value with default [default: true]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions