- Notifications
You must be signed in to change notification settings - Fork 413
Closed
Labels
Milestone
Description
When an option is marked Required and a DefaultValueFactory is set, calling Option.GetRequiredValue still throws.
Program code:
using System.CommandLine; var rootCommand = new RootCommand("This is the description") { new Option<string>("--required") { Required = true, DefaultValueFactory = _ => "hello" } }; var parseResult = rootCommand.Parse("-h"); Console.WriteLine(parseResult.GetRequiredValue<string>("--required")); Exception:
Unhandled exception. System.InvalidOperationException: --required is required but was not provided. at System.CommandLine.Parsing.SymbolResult.GetRequiredValue[T](String name) at System.CommandLine.ParseResult.GetRequiredValue[T](String name) at Program.<Main>$(String[] args) in C:\temp\command-name-issue\Program.cs:line 14