Update help output for required options

This commit is contained in:
Patrik Svensson
2025-05-25 00:48:09 +02:00
committed by Patrik Svensson
parent 67c3909bbb
commit e4b5b56d93
10 changed files with 138 additions and 33 deletions

View File

@ -1,6 +1,13 @@
namespace Spectre.Console.Tests.Data;
public class RequiredOptionsSettings : CommandSettings
{
[CommandOption("--foo <VALUE>", true)]
[Description("Foos the bars")]
public string Foo { get; set; }
}
public class RequiredOptionsWithoutDescriptionSettings : CommandSettings
{
[CommandOption("--foo <VALUE>", true)]
public string Foo { get; set; }

View File

@ -0,0 +1,6 @@
USAGE:
myapp [OPTIONS]
OPTIONS:
-h, --help Prints help information
--foo <VALUE> Foos the bars. Required

View File

@ -0,0 +1,6 @@
USAGE:
myapp [OPTIONS]
OPTIONS:
-h, --help Prints help information
--foo <VALUE> Foos the bars. Required

View File

@ -0,0 +1,6 @@
USAGE:
myapp [OPTIONS]
OPTIONS:
-h, --help Prints help information
--foo <VALUE> Required

View File

@ -0,0 +1,6 @@
USAGE:
myapp [OPTIONS]
OPTIONS:
-h, --help Prints help information
--foo <VALUE> Required

View File

@ -1061,5 +1061,43 @@ public sealed partial class CommandAppTests
// Then
return Verifier.Verify(result.Output);
}
[Fact]
[Expectation("Required_Options")]
public Task Should_Show_Required_Options()
{
// Given
var fixture = new CommandAppTester();
fixture.SetDefaultCommand<GenericCommand<RequiredOptionsSettings>>();
fixture.Configure(configurator =>
{
configurator.SetApplicationName("myapp");
});
// When
var result = fixture.Run("--help");
// Then
return Verifier.Verify(result.Output);
}
[Fact]
[Expectation("Required_Options_No_Description")]
public Task Should_Show_Required_Options_Without_Description()
{
// Given
var fixture = new CommandAppTester();
fixture.SetDefaultCommand<GenericCommand<RequiredOptionsWithoutDescriptionSettings>>();
fixture.Configure(configurator =>
{
configurator.SetApplicationName("myapp");
});
// When
var result = fixture.Run("--help");
// Then
return Verifier.Verify(result.Output);
}
}
}

View File

@ -1,4 +1,4 @@
namespace Spectre.Console.Cli.Tests.Unit.Testing;
namespace Spectre.Console.Tests.Unit.Cli;
public sealed class InteractiveCommandTests
{