-
Notifications
You must be signed in to change notification settings - Fork 413
Open
Description
If an IEnumerable type argument is defined, the error message "Required argument missing for command" will not be shown; instead, it will directly throw an error.
Argument<string[]> argument = new("test argument");
RootCommand rootCommand = new RootCommand("Test") { argument };
rootCommand.SetAction(result => Console.WriteLine(result.GetRequiredValue(argument)));
await rootCommand.Parse(args).InvokeAsync();
If you run the example above, an error will occur.
Unhandled exception: System.InvalidOperationException: test argument is required but was not provided.
at System.CommandLine.Parsing.SymbolResult.GetRequiredValue[T](Argument`1 argument)
at System.CommandLine.ParseResult.GetRequiredValue[T](Argument`1 argument)
at Program.<>c__DisplayClass0_0.<<Main>$>b__0(ParseResult result) in D:\Dev\Study\ConsoleApp1\Program.cs:line 5
at System.CommandLine.Command.<>c__DisplayClass30_0.<SetAction>b__0(ParseResult context)
at System.CommandLine.Invocation.AnonymousSynchronousCommandLineAction.Invoke(ParseResult parseResult)
at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
If the Argument is changed to string, no error will occur.
My English is not very good, so I used an AI translator. Please let me know if I haven't expressed myself clearly.
Metadata
Metadata
Assignees
Labels
No labels