Closed Tyrrrz closed 1 year ago
C#11 added the required keyword for properties:
required
[Command] public class AuthCommand : ICommand { [CommandOption("token", IsRequired = true, EnvironmentVariable = "AUTH_TOKEN")] public required string AuthToken { get; init; } public ValueTask ExecuteAsync(IConsole console) { console.Output.WriteLine(AuthToken); return default; } }
We should default the value of the IsRequired property on the CommandOption attribute to true (instead of false) if the required keyword is used.
IsRequired
CommandOption
true
false
This keyword can be detected through reflection by looking for the RequiredMember attribute:
RequiredMember
C#11 added the
required
keyword for properties:We should default the value of the
IsRequired
property on theCommandOption
attribute totrue
(instead offalse
) if therequired
keyword is used.This keyword can be detected through reflection by looking for the
RequiredMember
attribute: