We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
This very simple command takes four arguments, the first three being mandatory.
When the last argument (arg4) is omitted, the handler receives the value of arg2 instead of null.
var root = new RootCommand(); var arg1 = new Argument<string>("arg1") { Arity = ArgumentArity.ExactlyOne }; var arg2 = new Argument<string>("arg2") { Arity = ArgumentArity.ExactlyOne }; var arg3 = new Argument<string>("arg3") { Arity = ArgumentArity.ExactlyOne }; var arg4 = new Argument<string>("arg4") { Arity = ArgumentArity.ZeroOrOne }; root.AddArgument(arg1); root.AddArgument(arg2); root.AddArgument(arg3); root.AddArgument(arg4); root.SetHandler((v1, v2, v3, v4) => { Console.WriteLine($"arg1: {v1}\narg2: {v2}\narg3: {v3}\narg4: {v4}"); }, arg1, arg2, arg3, arg4); root.Invoke(["one", "TWO", "three"]);
This prints:
arg1: one arg2: TWO arg3: three arg4: TWO
Expected: arg4 = null. Or, if I misunderstood how to set up such a syntax, a runtime exception. But certainly not "TWO".
It's possible to work around this by adding an explicit default to arg4:
var arg4 = new Argument<string>("arg4", () => null) { Arity = ArgumentArity.ZeroOrOne };
Version: 2.0.0-beta4.22272.1
The text was updated successfully, but these errors were encountered:
No branches or pull requests
This very simple command takes four arguments, the first three being mandatory.
When the last argument (arg4) is omitted, the handler receives the value of arg2 instead of null.
This prints:
Expected: arg4 = null. Or, if I misunderstood how to set up such a syntax, a runtime exception. But certainly not "TWO".
It's possible to work around this by adding an explicit default to arg4:
Version: 2.0.0-beta4.22272.1
The text was updated successfully, but these errors were encountered: