fsprojects / Argu

A declarative CLI argument parser for F#
https://fsprojects.github.io/Argu
MIT License
451 stars 75 forks source link

chore(Tests): Add learning/doc test re AltCommandLine `-d` #232

Closed bartelink closed 6 months ago

bartelink commented 6 months ago

I got tied up in knots suspecting a bug in Argu using locally installed dotnet tools (I always install globally and hence it just works)

Invocation was

propulsion sync cosmos -s $EQUINOX_COSMOS_CONNECTION -d $EQUINOX_COSMOS_DATABASE -c $EQUINOX_COSMOS_CONTAINER  \
    from cosmos -s $EQUINOX_COSMOS_CONNECTION -d sourcedb -c sourcecontainer

So I added naively added a dotnet before toolname to shut it up

Which resulted in a ERROR: unrecognized argument: 'equinox-common-test'. message

Which could only be fixed by replacing the two -d cases (which are AltCommandLine aliases) with the raw name (--database)

Hence this test, which proves nothing new, except that it's pretty naive to assume that Eirik left some wacky bugs in here!

Of course the actual problem is my stupidity, which has a proposed solution: https://github.com/dotnet/sdk/issues/14626

The real solution until that issue is addressed in 14626 is to prefix local runs with dotnet tool run

bartelink commented 6 months ago

One more way of getting stung by the same thing is to naively do dotnet run toolname <args>, which, for the above yields: (coz dotnet run has a -c switch but no -d!)

System.InvalidOperationException: Option '-c' only accepts a single argument but 2 were provided.
   at System.CommandLine.Binding.ArgumentConverter.GetValueOrDefault[T](ArgumentConversionResult result)
   at System.CommandLine.Parsing.OptionResult.GetValueOrDefault[T]()
   at System.CommandLine.Parsing.SymbolResult.GetValueForOption(Option option)
   at System.CommandLine.ParseResult.GetValueForOption(Option option)