command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

If an optional positional argument is not specified it may incorrectly be filled with another argument

Open mitchcapper opened this issue 2 years ago • 3 comments

Can put together a repro case if this bug is not obvious (and im not making a mistake) but it seems pretty easy to cause.

Given the args array to InvokeAsync of: image

It assigns the value that is properly assigned to the Program argument also to the not-specified positional arg zArgs image

Help output to better illustrate:

Usage:
  TestApp Monitor <File> <Program> [<ZArgs>] [options]

Arguments:
  <File>     File or folder
  <Program>  Program path
  <ZArgs>    Arg string to pass

Options:
  --Debug                turn on debug mode

If a value is given for that it does parse correctly:

image

Running: 2.0.0-beta4.22272.1

mitchcapper avatar Oct 21 '22 09:10 mitchcapper

Can you share your test code so we can more easily reproduce this?

KathleenDollard avatar Oct 26 '22 18:10 KathleenDollard

No problem attached.

Here is the output generated.

Invoking with args: c:\temp\monitttest, ping
For child: File has value: c:\temp\monitttest
For child: Program has value: ping
For child: ZArgs has value: ping

Note if you only have one required arg rather than two it does not seem to happen (ie removing the program one) Program.cs.txt

mitchcapper avatar Oct 27 '22 22:10 mitchcapper

Hi,

Just to add another use case.

I have the following Command:

Command abc Arguments: string arg1 string arg2

Options: string --opt1 string --opt2

when invoking with invalid options: abc --opt3 value3

these values will be considered the value of the arguments arg1 and arg2.

I have done some debugging and it seems that in the Tokenize method, every time that a token is not in the RootCommand.ValidTokens() is considered an Argument.

joaoopereira avatar Aug 23 '23 11:08 joaoopereira