dotnet / dotnet/command-line-api

"--version option cannot be combined with other arguments." is not displayed when "--help" is also specified

Open
#2,501 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Hi.

Thank you for System.CommandLine.

The error message "--version option cannot be combined with other arguments." is not displayed when "--help" is also specified on the command line.

Steps to reproduce:

1. Build console app with Program.cs:
```
internal class Program
{
static async Task Main(string[] args)
{
RootCommand rootCommand = new RootCommand();

var option = new Option("--option1");

rootCommand.Add(option);

rootCommand.Handler = CommandHandler.Create(() =>
{
Console.WriteLine("Hello, World!");
});

return await rootCommand.InvokeAsync(args);
}
}
```

2. Run `ConsoleApp1.exe --option1 --version`
Notice the error `--version option cannot be combined with other arguments.`
This is expected behavior.

3. Run `ConsoleApp10.exe --help --version`
Notice the error is not displayed.
Only the version is displayed.
This is unexpected behavior; I expected the error `--version option cannot be combined with other arguments.`.

4. Run `ConsoleApp10.exe --option1 --help --version`
Notice the error is not displayed.
Only the version is displayed.
This is unexpected behavior; I expected the error `--version option cannot be combined with other arguments.`.

System.CommandLine 2.0.0-beta4.22272.1

Thank you.

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.