dotnet / dotnet/command-line-api

Parsing gives incorrect/unexpected/inconsistent error results

Open
#2,664 8 comments 0 reactions 0 assignees View on GitHub
Area-Parser and Binder
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Version: 2.0.0-beta7.25380.108 (Latest NuGet as of this writing)

``` C#
[TestMethod]
public void RawApi_Version_Error_tests( )
{
var rootCommand = new RootCommand("Test Root")
{
new Option("--option1")
{
Description = "Test option `",
Required = true,
},
};

var result = rootCommand.Parse(["--FooBar", "--version"]);
Assert.HasCount( 3, result.Errors, "Errors should account for, bogus arg (`--FooBar`), missing required arg (`--option1`), AND that `--version` should be solo" );
}
```

This test won't pass, the error count is only 2, the error regarding the `--version` is completely missing.
Errors are:
[0] = "Unrecognized command or argument '--FooBar'."
[1] = "Option '--option1' is required."

For help it's even worse...
``` C#
[TestMethod]
public void RawApi_Help_Error_tests( )
{
var rootCommand = new RootCommand("Test Root")
{
new Option("--option1")
{
Description = "Test option `",
Required = true,
},
};

var result = rootCommand.Parse(["--FooBar", "--help"]);
Assert.HasCount( 3, result.Errors, "Errors should account for, bogus arg (`--FooBar`), missing required arg (`--option1`), AND that `--version` should be solo" );
}
```

This results in NO errors. But the expectation is that an error for the bogus param AND the missing required argument is present. Basically, the problem is one of co-mingling parsing (which is really lex+parse) with validation which is semantic analysis and is VERY application dependent. Ideally, there is a way to disable all validations and move that to a distinct operation the application is in control of.

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.