Skip to content

FromAmong appends values rather than replaces them #1837

Closed
@Keboo

Description

@Keboo

Consider the following code:

using System.CommandLine;

Option<Pet> petOption = new("--pet");
petOption.FromAmong(Pet.Dog.ToString(), Pet.Cat.ToString());
RootCommand rootCommand = new()
{
    petOption
};

rootCommand.Invoke(args);


enum Pet
{
    Unknown,
    Dog, 
    Cat
}

This produces the following help output:

Description:

Usage:
  ConsoleApp2 [options]

Options:
  --pet <Cat|Dog|Unknown>
  --version                Show version information
  -?, -h, --help           Show help and usage information

FromAmong is documented as

Configures an option to accept only the specified values, and to suggest them as command line completions.

I expected it to override the default behavior of an enum option and use only the values that I specified.
This issue cam about because I was looking for a way to remove/overwrite the default completions that are generated for an Option's Argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompletionsRelated to support for tab completionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions