mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00
Completed
This commit is contained in:
parent
d03c10623c
commit
55c763a5c2
@ -27,14 +27,34 @@ internal sealed class CommandExecutor
|
|||||||
_registrar.RegisterInstance(typeof(CommandModel), model);
|
_registrar.RegisterInstance(typeof(CommandModel), model);
|
||||||
_registrar.RegisterDependencies(model);
|
_registrar.RegisterDependencies(model);
|
||||||
|
|
||||||
|
// No default command?
|
||||||
|
if (model.DefaultCommand == null)
|
||||||
|
{
|
||||||
|
// Got at least one argument?
|
||||||
|
var firstArgument = args.FirstOrDefault();
|
||||||
|
if (firstArgument != null)
|
||||||
|
{
|
||||||
// Asking for version? Kind of a hack, but it's alright.
|
// Asking for version? Kind of a hack, but it's alright.
|
||||||
// We should probably make this a bit better in the future.
|
// We should probably make this a bit better in the future.
|
||||||
if (args.Contains("-v") || args.Contains("--version"))
|
if (firstArgument.Equals("--version", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
firstArgument.Equals("-v", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var console = configuration.Settings.Console.GetConsole();
|
var console = configuration.Settings.Console.GetConsole();
|
||||||
console.WriteLine(ResolveApplicationVersion(configuration));
|
console.WriteLine(ResolveApplicationVersion(configuration));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//// Asking for version? Kind of a hack, but it's alright.
|
||||||
|
//// We should probably make this a bit better in the future.
|
||||||
|
//if (args.Count() > 0 &&
|
||||||
|
// (args.First().Equals("-v", StringComparison.OrdinalIgnoreCase) || args.First().Equals("--version", StringComparison.OrdinalIgnoreCase)))
|
||||||
|
//{
|
||||||
|
// var console = configuration.Settings.Console.GetConsole();
|
||||||
|
// console.WriteLine(ResolveApplicationVersion(configuration));
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
|
||||||
// Parse and map the model against the arguments.
|
// Parse and map the model against the arguments.
|
||||||
var parsedResult = ParseCommandLineArguments(model, configuration.Settings, args);
|
var parsedResult = ParseCommandLineArguments(model, configuration.Settings, args);
|
||||||
|
@ -35,7 +35,7 @@ public sealed partial class CommandAppTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Output_Application_Version_To_The_Console_With_Command()
|
public void Should_Execute_Command_Not_Output_Application_Version_To_The_Console()
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
@ -50,11 +50,12 @@ public sealed partial class CommandAppTests
|
|||||||
var result = fixture.Run("empty", "--version");
|
var result = fixture.Run("empty", "--version");
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.Output.ShouldBe("1.0");
|
result.Output.ShouldBe(string.Empty);
|
||||||
|
result.Context.ShouldHaveRemainingArgument("version", new[] { (string)null });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Output_Application_Version_To_The_Console_With_Default_Command()
|
public void Should_Execute_Default_Command_Not_Output_Application_Version_To_The_Console()
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
@ -68,7 +69,8 @@ public sealed partial class CommandAppTests
|
|||||||
var result = fixture.Run("--version");
|
var result = fixture.Run("--version");
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.Output.ShouldBe("1.0");
|
result.Output.ShouldBe(string.Empty);
|
||||||
|
result.Context.ShouldHaveRemainingArgument("version", new[] { (string)null });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user