3 Commits
2.0.2 ... 2.0.3

Author SHA1 Message Date
Tyrrrz
595805255a Update version 2021-04-09 22:24:06 +03:00
Tyrrrz
65eaa912cf Refactor 2021-04-08 20:53:48 +03:00
Robert Dailey
038f48b78e Show choices on non-scalar enum parameters and options (#102) 2021-04-08 20:51:17 +03:00
4 changed files with 56 additions and 4 deletions

View File

@@ -1,3 +1,7 @@
### v2.0.3 (09-Apr-2021)
- Improved help text by showing valid values for non-scalar enum parameters and options. (Thanks [@Robert Dailey](https://github.com/rcdailey))
### v2.0.2 (31-Mar-2021)
- Fixed an issue where having a transitive reference to CliFx sometimes resulted in `SystemConsoleShouldBeAvoidedAnalyzer` throwing `NullReferenceException` during build.

View File

@@ -577,6 +577,51 @@ public class Command : ICommand
);
}
[Fact]
public async Task Help_text_shows_all_valid_values_for_non_scalar_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 List<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]
public async Task Help_text_shows_environment_variables_for_options_that_have_them_configured_as_fallback()
{
@@ -875,4 +920,4 @@ public class SecondCommandSecondChildCommand : ICommand
stdOut.Trim().Should().Be("v6.9");
}
}
}
}

View File

@@ -21,7 +21,10 @@ namespace CliFx.Schema
public IReadOnlyList<object?> GetValidValues()
{
var underlyingType = Type.TryGetNullableUnderlyingType() ?? Type;
var underlyingType =
Type.TryGetNullableUnderlyingType() ??
Type.TryGetEnumerableUnderlyingType() ??
Type;
// We can only get valid values for enums
if (underlyingType.IsEnum)
@@ -30,4 +33,4 @@ namespace CliFx.Schema
return Array.Empty<object?>();
}
}
}
}

View File

@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>2.0.2</Version>
<Version>2.0.3</Version>
<Company>Tyrrrz</Company>
<Copyright>Copyright (C) Alexey Golub</Copyright>
<LangVersion>latest</LangVersion>