dotnet / dotnet/command-line-api
Bool Arguments are optional while Int Arguments are not
- 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
Assessment
This issue has not been assessed yet.