mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Show choices for nullable enums in enumerable (#105)
This commit is contained in:
@@ -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<CustomEnum?> 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<string, string>()
|
||||||
|
);
|
||||||
|
|
||||||
|
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]
|
[Fact]
|
||||||
public async Task Help_text_shows_environment_variables_for_options_that_have_them_configured_as_fallback()
|
public async Task Help_text_shows_environment_variables_for_options_that_have_them_configured_as_fallback()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ namespace CliFx.Schema
|
|||||||
|
|
||||||
public IReadOnlyList<object?> GetValidValues()
|
public IReadOnlyList<object?> GetValidValues()
|
||||||
{
|
{
|
||||||
var underlyingType =
|
var underlyingType = Type.TryGetEnumerableUnderlyingType() ?? Type;
|
||||||
Type.TryGetNullableUnderlyingType() ??
|
underlyingType = underlyingType.TryGetNullableUnderlyingType() ?? underlyingType;
|
||||||
Type.TryGetEnumerableUnderlyingType() ??
|
|
||||||
Type;
|
|
||||||
|
|
||||||
// We can only get valid values for enums
|
// We can only get valid values for enums
|
||||||
if (underlyingType.IsEnum)
|
if (underlyingType.IsEnum)
|
||||||
|
|||||||
Reference in New Issue
Block a user