mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Fix ordering of parameters within command help usage (#118)
This commit is contained in:
@@ -223,6 +223,56 @@ public class NamedChildCommand : ICommand
|
|||||||
stdErr.Should().NotBeNullOrWhiteSpace();
|
stdErr.Should().NotBeNullOrWhiteSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for #117
|
||||||
|
[Fact]
|
||||||
|
public async Task Help_text_lists_parameters_in_specified_order()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
|
// language=cs
|
||||||
|
@"
|
||||||
|
public abstract class CommandBase : ICommand
|
||||||
|
{
|
||||||
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
|
|
||||||
|
public abstract ValueTask ExecuteAsync(IConsole console);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command]
|
||||||
|
public class Command : CommandBase
|
||||||
|
{
|
||||||
|
[CommandParameter(1)]
|
||||||
|
public string Bar { get; set; }
|
||||||
|
|
||||||
|
[CommandParameter(2)]
|
||||||
|
public IReadOnlyList<string> Baz { get; set; }
|
||||||
|
|
||||||
|
public override 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(
|
||||||
|
"USAGE",
|
||||||
|
"<foo>", "<bar>", "<baz...>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Help_text_shows_application_metadata()
|
public async Task Help_text_shows_application_metadata()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,13 +106,13 @@ internal static class DynamicCommandBuilder
|
|||||||
// Return all defined commands
|
// Return all defined commands
|
||||||
var commandTypes = generatedAssembly
|
var commandTypes = generatedAssembly
|
||||||
.GetTypes()
|
.GetTypes()
|
||||||
.Where(t => t.IsAssignableTo(typeof(ICommand)))
|
.Where(t => t.IsAssignableTo(typeof(ICommand)) && !t.IsAbstract)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
if (commandTypes.Length <= 0)
|
if (commandTypes.Length <= 0)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
"There are no command definitions in the provide source code."
|
"There are no command definitions in the provided source code."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ internal static class DynamicCommandBuilder
|
|||||||
if (commandTypes.Count > 1)
|
if (commandTypes.Count > 1)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
"There are more than one command definitions in the provide source code."
|
"There are more than one command definitions in the provided source code."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ internal partial class CommandSchema
|
|||||||
var parameterSchemas = type.GetProperties()
|
var parameterSchemas = type.GetProperties()
|
||||||
.Select(ParameterSchema.TryResolve)
|
.Select(ParameterSchema.TryResolve)
|
||||||
.Where(p => p is not null)
|
.Where(p => p is not null)
|
||||||
|
.OrderBy(p => p!.Order)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var optionSchemas = type.GetProperties()
|
var optionSchemas = type.GetProperties()
|
||||||
|
|||||||
Reference in New Issue
Block a user