mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-08-03 02:17:59 +08:00
Add support for required options
This commit is contained in:

committed by
Patrik Svensson

parent
d836ad1805
commit
67c3909bbb
@ -0,0 +1,7 @@
|
||||
namespace Spectre.Console.Tests.Data;
|
||||
|
||||
public class RequiredOptionsSettings : CommandSettings
|
||||
{
|
||||
[CommandOption("--foo <VALUE>", true)]
|
||||
public string Foo { get; set; }
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
namespace Spectre.Console.Tests.Unit.Cli;
|
||||
|
||||
public sealed partial class CommandAppTests
|
||||
{
|
||||
public sealed class Options
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Throw_If_Required_Option_Is_Missing()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.AddCommand<GenericCommand<RequiredOptionsSettings>>("test");
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => fixture.Run("test"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<CommandRuntimeException>()
|
||||
.And(ex =>
|
||||
ex.Message.ShouldBe("Command 'test' is missing required argument 'foo'."));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace Spectre.Console.Tests.Unit.Cli;
|
||||
|
||||
public sealed partial class CommandApptests
|
||||
public sealed partial class CommandAppTests
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Treat_Commands_As_Case_Sensitive_If_Specified()
|
||||
|
Reference in New Issue
Block a user