commandline icon indicating copy to clipboard operation
commandline copied to clipboard

unused positional argument / value

Open theKBro opened this issue 3 years ago • 2 comments

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?

theKBro avatar Sep 15 '22 20:09 theKBro

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"
  }
}

hallipr avatar Feb 23 '23 21:02 hallipr

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.

georghinkel avatar Mar 23 '23 14:03 georghinkel