Skip to content

Help output for enum-type option with ArgumentArity.Zero suggests values for it regardless of the option arity being zero #2296

@elgonzo

Description

@elgonzo

System.CommandLine version: 2.0.0-beta6.25320.118

Defining an CliOption<T> with an enum type and its arity being set to ArgumentArity.Zero, the help output nevertheless suggests the option accepts values despite its arity being set to ArgumentArity.Zero and it not really accepting any values.

Looking at the code that generates the help output, the suggested values seem to come from a completion source. While i haven't tested completions myself, this suggests that not only help output but also completions for such options is broken.

Code to reproduce

Note that all options have an arity of Zero and a custom parser that produces the set/combination of animals the respective option represents.

var optionCarnivores = new Option<Animals>("-c")
{
    Description = "Select carnivores",
    Arity = ArgumentArity.Zero,
    CustomParser = _ => Animals.Cat | Animals.Dog | Animals.Gecko
};

var optionInsectivores = new Option<Animals>("-i")
{
    Description = "Select insectivores",
    Arity = ArgumentArity.Zero,
    CustomParser = _ => Animals.Gecko
};

var optionHerbivores = new Option<Animals>("-h")
{
    Description = "Select herbivores",
    Arity = ArgumentArity.Zero,
    CustomParser = _ => Animals.Giraffe | Animals.Gnu
};

var rootCmd = new RootCommand
{
    optionCarnivores,
    optionInsectivores,
    optionHerbivores
};

rootCmd.Parse("--help").Invoke();


[Flags]
public enum Animals
{
    Cat = 1,
    Dog = 2,
    Gecko = 4,
    Giraffe = 8,
    Gnu = 16
}

Expected help output for the -c, -i, -h option

  -c                     Select carnivores
  -i                     Select insectivores
  -h                     Select herbivores

Actual help output

  -c <Cat|Dog|Gecko|Giraffe|Gnu>  Select carnivores
  -i <Cat|Dog|Gecko|Giraffe|Gnu>  Select insectivores
  -h <Cat|Dog|Gecko|Giraffe|Gnu>  Select herbivores

This help output is incorrect, as the options -c, -i and -h do not accept any values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions