diff --git a/CliFx.Tests/HelpTextSpecs.cs b/CliFx.Tests/HelpTextSpecs.cs index 8a1e08f..cf9a646 100644 --- a/CliFx.Tests/HelpTextSpecs.cs +++ b/CliFx.Tests/HelpTextSpecs.cs @@ -622,6 +622,51 @@ public class Command : ICommand ); } + [Fact] + public async Task Help_text_shows_all_valid_values_for_nullable_enum_parameters_and_options() + { + // Arrange + var commandType = DynamicCommandBuilder.Compile( + // language=cs + @" +public enum CustomEnum { One, Two, Three } + +[Command] +public class Command : ICommand +{ + [CommandParameter(0)] + public CustomEnum? Foo { get; set; } + + [CommandOption(""bar"")] + public List Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; +} +"); + + var application = new CliApplicationBuilder() + .AddCommand(commandType) + .UseConsole(FakeConsole) + .Build(); + + // Act + var exitCode = await application.RunAsync( + new[] {"--help"}, + new Dictionary() + ); + + var stdOut = FakeConsole.ReadOutputString(); + + // Assert + exitCode.Should().Be(0); + stdOut.Should().ContainAllInOrder( + "PARAMETERS", + "foo", "Choices:", "One", "Two", "Three", + "OPTIONS", + "--bar", "Choices:", "One", "Two", "Three" + ); + } + [Fact] public async Task Help_text_shows_environment_variables_for_options_that_have_them_configured_as_fallback() { diff --git a/CliFx/Schema/BindablePropertyDescriptor.cs b/CliFx/Schema/BindablePropertyDescriptor.cs index 4aa7447..6eacafa 100644 --- a/CliFx/Schema/BindablePropertyDescriptor.cs +++ b/CliFx/Schema/BindablePropertyDescriptor.cs @@ -21,10 +21,8 @@ namespace CliFx.Schema public IReadOnlyList GetValidValues() { - var underlyingType = - Type.TryGetNullableUnderlyingType() ?? - Type.TryGetEnumerableUnderlyingType() ?? - Type; + var underlyingType = Type.TryGetEnumerableUnderlyingType() ?? Type; + underlyingType = underlyingType.TryGetNullableUnderlyingType() ?? underlyingType; // We can only get valid values for enums if (underlyingType.IsEnum)