Skip to content

Required Arguments (ExactlyOne arity) aren't being validated if not supplied #484

@watermelonpizza

Description

@watermelonpizza

If you create a command with an option and its arity is ExactlyOne it will not be validated if the option isn't supplied in the arguments.

For example:

var command = new Command("team")
{
    new Option("--sport", argument: new Argument<string> { Arity = ArgumentArity.ExactlyOne })
};

command.Handler = CommandHandler.Create(async (string sport) => 
{
   // sport is null
   ...
}

If you call the application with myapp team there is no validation performed against --sport so it can slip through as null in the handler.

If supplied i.e. myapp team --sport then you get validation:

Required argument missing for option: --sport

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