Add support for converting command parameters into FileInfo and DirectoryInfo (#1145)

Add support for converting command parameters that doesn't have a built-in TypeConverter but has a constructor that takes a string. For CLI apps, FileInfo and DirectoryInfo will likely be the most useful ones, but there may be others.
This commit is contained in:
Cédric Luthi
2023-03-01 13:02:43 +01:00
committed by GitHub
parent 6740f0b02b
commit d3f4f5f208
6 changed files with 63 additions and 11 deletions

View File

@ -1,3 +1,5 @@
using System.IO;
namespace Spectre.Console.Tests.Unit.Cli;
public sealed partial class CommandAppTests
@ -76,5 +78,27 @@ public sealed partial class CommandAppTests
result.Output.ShouldContain(nameof(DayOfWeek.Friday));
result.Output.ShouldContain(nameof(DayOfWeek.Saturday));
}
[Fact]
public void Should_Convert_FileInfo_And_DirectoryInfo()
{
// Given
var app = new CommandAppTester();
app.Configure(config =>
{
config.AddCommand<HorseCommand>("horse");
});
// When
var result = app.Run(new[] { "horse", "--file", "ntp.conf", "--directory", "etc" });
// Then
result.ExitCode.ShouldBe(0);
result.Settings.ShouldBeOfType<HorseSettings>().And(horse =>
{
horse.File.Name.ShouldBe("ntp.conf");
horse.Directory.Name.ShouldBe("etc");
});
}
}
}