commandline
commandline copied to clipboard
unused positional argument / value
I got no parsing error if a positional argument is present
example: no value/positional arguments allowed at all
option with space abc.exe -t myPath/with a/unwandted/space
so the option is myPath/with and the rest is completely lost without an error
Am I missing a special configuration here?
I'm also seeing unprocessed Values handled as valid but ignored even if IgnoreUnknownArguments == false.
void Main()
{
var jsonOptions = new JsonSerializerOptions { WriteIndented = true, Converters = { new JsonStringEnumConverter() } };
var args = new[] { "verb", "verbValue0", "verbValue1", "--option", "optionArg" };
var parser = new Parser(settings =>
{
settings.CaseSensitive = false;
settings.HelpWriter = Console.Out;
settings.IgnoreUnknownArguments = false;
});
var result = parser.ParseArguments<VerbOptions, object>(args);
Console.WriteLine(JsonSerializer.Serialize(new { result.Errors, result.Tag, result.Value }, jsonOptions));
}
[Verb("verb")]
class VerbOptions
{
// [Value(0)]
// public IEnumerable<string> VerbValues { get; set; }
[Option]
public string Option { get; set; }
}
outputs:
{
"Errors": [],
"Tag": "Parsed",
"Value": {
"Option": "optionArg"
}
}
The tokens verbValue0 and verbValue1 are ignored here. If you uncomment the VerbValues property, the tokens appear in the result:
{
"Errors": [],
"Tag": "Parsed",
"Value": {
"VerbValues": [
"verbValue0",
"verbValue1"
],
"Option": "optionArg"
}
}
I also had this issue. I was taking a look into the code and there is currently no way to determine whether the values have been consumed or not. I added a PR to fix the issue. Hope it will be reviewed soonish.