-
Notifications
You must be signed in to change notification settings - Fork 375
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
Duplicate "--version" keys #1691
Comments
Can you provide a code sample to reproduce this? |
Full sample code can be found here: https://gist.github.com/mmckechney/7bd92a4417458fb8b919b44bac5c5b89 In creating this sample I discovered the root of the problem: The use of the //This throws exception with: "One or more errors occurred. (An item with the same key has already been added. Key: --version)'"
var parser = new CommandLineBuilder(rootCommand)
.UseDefaults()
.UseHelp(ctx =>
{
ctx.HelpBuilder.CustomizeLayout(_ => System.CommandLine.Help.HelpBuilder.Default
.GetLayout()
.Prepend(
_ => _.Output.WriteLine("**Adding extra help here**")
));
}).Build(); However: I also noticed that if you remove the //This runs, but the help output is not modified as expected
var parser = new CommandLineBuilder(rootCommand)
.UseHelp(ctx =>
{
ctx.HelpBuilder.CustomizeLayout(_ => System.CommandLine.Help.HelpBuilder.Default
.Prepend(
_ => _.Output.WriteLine("**Adding extra help here**")
));
}).Build(); |
Is there an update on this other than the milestone tag? Do we have any way to work around this? I'm experiencing the same problem. I just want to add a logo and copyright before description. |
I'm not seeing this issue when calling I do see it when I call That should allow people to work around this while we sort out the issue. |
For reference, this was also spotted by another user some months later: #1791 (comment) |
I am running into this in my application, but perhaps for slightly different reasons than the rest of you. I have a custom var versionOption = new Option<VoidObject>(new[] { "--version", "-v" }, "Show version information");
var rootCommand = new RootCommand { ... };
rootCommand.AddOption(versionOption);
return new CommandLineBuilder(rootCommand)
.UseDefaults() // <-- this triggers the problem
.Build()
.Invoke(args, console); Changing from |
There is no UseHelp method any more. The CliRootCommand constructor now adds VersionOption. command-line-api/src/System.CommandLine/CliRootCommand.cs Lines 26 to 30 in 299ea1c
If you don't want the predefined behavior of VersionOption, you can do one of
But perhaps there is still something to improve in the error handling if duplicate --version options are added. |
Still same problem with version This is my RootCommand:
And this is how I call it:
|
Also using |
After updating to the latest release (System.CommandLine v2.0.0-beta3.22114.1), I am now getting the following error at runtime:
No other changes were made to the app that was previously working. I do use
System.CommandLine.NamingConventionBinder
to be compatible with the olderCommandHandler.Create
model, could this be the problem?The text was updated successfully, but these errors were encountered: