You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Passing extra arguments after "help (verb)" causes an InvalidOperationException #225
Using CommandLineParser 2.0.235.0 beta, I can cause an InvalidOperationException by simply running "my-cmd.exe help verb foo" instead of "my-cmd.exe help verb". "my-cmd.exe help verb" produces the expected help text, but "my-cmd.exe help verb foo" produces the following exception:
Unhandled Exception: System.InvalidOperationException: Sequence contains more than one element
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at CommandLine.Core.InstanceChooser.<>c__DisplayClass0_0.<Choose>b__0()
at CommandLine.Core.InstanceChooser.Choose(Func`3 tokenizer, IEnumerable`1 types, IEnumerable`1 arguments, StringComparer nameComparer, CultureInfo parsingCulture, IEnumerable`1 nonFatalErrors)
at CommandLine.Parser.<>c__DisplayClass13_0.<ParseArguments>b__0()
at CommandLine.Parser.MakeParserResult[T](Func`1 parseFunc, ParserSettings settings)
at TryOutCommandLineParser.Program.Main(String[] args) in c:\src\try\TryOutCommandLineParser\Program.cs:line 17
Running "my-cmd.exe verb foo --help" works, sort of (I don't like the "Option 'help' is unknown) error, but I can live with it. But I'm pretty sure that users will at one point try replacing "my-cmd.exe verb foo bar -v" with "my-cmd.exe help verb foo bar -v" to get help usage, and I'd like this to be handled. So when the "help" verb is invoked, I'd like it to ignore any further arguments, but not throw an exception if they are present.
--help is enumerated as an option because the canonical help request, requires you to put "--help" as first argument. In this case the help screen is showed not because you added "--help" but because the command line syntax rules are not respected.
I need reason a little more on this... The main issue anyway is fixed, in seconds I'll merge to master...
Activity
gsscoder commentedon Aug 19, 2015
@rmunn, thanks for detailed reporting, I'll try fix both issues (the exception and
helpunknown).I'll update you here.
Thanks, again!
Added failing test for Issue #225
Issue #225 Fixed
Checked correct output for Issue #225 test
gsscoder commentedon Aug 19, 2015
When you invoke your app with:
--help is enumerated as an option because the canonical help request, requires you to put "--help" as first argument. In this case the help screen is showed not because you added "--help" but because the command line syntax rules are not respected.
I need reason a little more on this... The main issue anyway is fixed, in seconds I'll merge to master...
gsscoder commentedon Aug 19, 2015
Version 2.0.239-beta fixes the issue (just released to NuGet), if this works can you please close the issue?
Thanks, @rmunn.
rmunn commentedon Aug 19, 2015
Regarding
--help, the logic I've come to expect from a verb-using command-line program like git is the following:--argument, if present) for a-hor--helpargument.-hor--helpwas present, process the verb's normal arguments.For example:
Whereas:
But the
--helpargument, and how to treat it, should probably be discussed in a separate issue.rmunn commentedon Aug 19, 2015
I've tested version 2.0.239-beta, and it works the way I want now (barring the "Option 'help' is unknown" error). This issue is fixed.
Added failing test for Issue #225/b
Fixed Issue #225/b
gsscoder commentedon Aug 19, 2015
@rmunn, after some reasoning I'm agree with you that listing
helpas unknown option is senseless.This is now fixed in version 2.0.241-beta on master and released to NuGet.
Anyway an eventual
-hwill not be removed because, this is not a built-in command for requesting help.If you're interested in internals:
this is the test -> https://github.com/gsscoder/commandline/blob/master/tests/CommandLine.Tests/Unit/ParserTests.cs#L542
this is the fix -> https://github.com/gsscoder/commandline/blob/master/src/CommandLine/ErrorExtensions.cs#L23
Bye! :)