Skip to content
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

Default IsRequired for options based on whether the required modifier is used on the property #132

Closed
Tyrrrz opened this issue Dec 8, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Tyrrrz
Copy link
Owner

Tyrrrz commented Dec 8, 2022

C#11 added the required keyword for properties:

[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.

This keyword can be detected through reflection by looking for the RequiredMember attribute:

image

@Tyrrrz Tyrrrz added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Dec 8, 2022
@Tyrrrz Tyrrrz changed the title Default option IsRequired based on whether the required modifier is used Default IsRequired for options based on whether the required modifier is used on the property Dec 8, 2022
@Tyrrrz Tyrrrz closed this as completed in b10577f Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant