dotnet / dotnet/command-line-api

Bool Arguments are optional while Int Arguments are not

Open
#1,158 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Consider the following application:

```c#
static int Main(string[] args)
{
var rootCommand = new RootCommand
{
new Argument("value", "Some value"),
//new Argument("value", "Some value"),
};

rootCommand.Handler = CommandHandler.Create(value =>
//rootCommand.Handler = CommandHandler.Create(value =>
{
Console.WriteLine($"The value for 'value' is: {value}");
});

return rootCommand.Invoke(args);
}
```

When calling this application **without any arguments**, you'll see something like this:

```
The value for 'value' is: False
```

So the argument is **optional by default**.

If, on the other hand, the parameter is defined as `Argument` (rather than `Argument`) and you call the application **without any arguments**, you'll see something like this:

```
Required argument missing for command: CommandLineReproducer
```

So, in this case the Argument is **required by default**.

I think this could be confusing (I certainly was to me). I'd say Arguments without default value should always be "required". Otherwise what would be the way to mark an `Argument` as required?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.