subcommand help flags cause exception
See original GitHub issueWhen trying to use a help flag on a subcommand, I get an Unhandled Exception: System.InvalidOperationException: Sequence contains more than one matching element
error.
Example code:
using System;
using McMaster.Extensions.CommandLineUtils;
namespace updater
{
class Program
{
public static int Main(string[] args)
{
var app = new CommandLineApplication();
app.Name = "updater";
app.HelpOption(inherited: true);
app.Command("get", (getcmd) =>
{
getcmd.Description = "Gets a list of things.";
getcmd.HelpOption();
getcmd.OnExecute(() =>
{
getcmd.ShowHelp();
return 1;
});
});
app.OnExecute(() => {
app.ShowHelp();
return 1;
});
return app.Execute(args);
}
}
}
Here are the steps I am taking to create this:
> dotnet publish --self-contained -r win10-x64
> .\bin\Debug\netcoreapp2.0\win10-x64\publish\updater.exe get
> .\bin\Debug\netcoreapp2.0\win10-x64\publish\updater.exe get --help
It throws this exception:
Unhandled Exception: System.InvalidOperationException: Sequence contains more than one matching element
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessOption() in C:\projects\commandlineutils\src\CommandLineUtils\Internal\CommandLineProcessor.cs:line 156
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessNext() in C:\projects\commandlineutils\src\CommandLineUtils\Internal\CommandLineProcessor.cs:line 62
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.Process() in C:\projects\commandlineutils\src\CommandLineUtils\Internal\CommandLineProcessor.cs:line 35
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Parse(String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 532
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 597
at updater.Program.Main(String[] args) in P:\C#\updater\Program.cs:line 31
Here is my dotnet configuration:
> dotnet --info
.NET Command Line Tools (2.1.2)
Product Information:
Version: 2.1.2
Commit SHA-1 hash: 5695315371
Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.2\
Microsoft .NET Core Shared Framework Host
Version : 2.0.5
Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54
I very well could be doing something wrong, too.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
subcommand help flags cause exception · Issue #86
When trying to use a help flag on a subcommand, I get an Unhandled Exception: System.InvalidOperationException: Sequence contains more than one ...
Read more >argparse sub-commands and groups: Setting help-dialog ...
I have achieved this goal with one minor exception: In order to get the help dialog in its own group I must add...
Read more >Entering Performance Toolkit Subcommands from EXECs ...
The corresponding subcommand set a flag which would cause execution of the command (e.g. selection of a specific performance display) when the program...
Read more >subcommands
Package subcommands implements a simple way for a single command to have many subcommands, each of which takes arguments and so forth.
Read more >argparse — Parser for command-line options, arguments ...
For a more gentle introduction to Python command-line parsing, ... It supports positional arguments, options that accept values, and on/off flags:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mxplusb the simplest fix here for you is to only have one call to
.HelpOption
. If you callapp.HelpOption(inherited: true)
on your top level command, you don’t need to call .HelpOption on any of the subcommand objects.Thanks @handcraftedsource! Yes, this is a good place to start.