Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused positional argument / value #847

Open
theKBro opened this issue Sep 15, 2022 · 2 comments · May be fixed by #881
Open

unused positional argument / value #847

theKBro opened this issue Sep 15, 2022 · 2 comments · May be fixed by #881

Comments

@theKBro
Copy link

theKBro commented Sep 15, 2022

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?

@hallipr
Copy link

hallipr commented Feb 23, 2023

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

@georghinkel
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants