mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Fix not printing version when requested if used with stub default command
This commit is contained in:
@@ -11,6 +11,8 @@ namespace CliFx.Tests
|
||||
[TestFixture]
|
||||
public partial class CliApplicationTests
|
||||
{
|
||||
private const string TestVersionText = "v1.0";
|
||||
|
||||
private static IEnumerable<TestCaseData> GetTestCases_RunAsync()
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
@@ -24,6 +26,18 @@ namespace CliFx.Tests
|
||||
new[] {"cmd"},
|
||||
"NamedCommand executed."
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new[] {"--version"},
|
||||
TestVersionText
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {"--version"},
|
||||
TestVersionText
|
||||
);
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> GetTestCases_RunAsync_Smoke()
|
||||
@@ -143,6 +157,7 @@ namespace CliFx.Tests
|
||||
|
||||
var application = new CliApplicationBuilder()
|
||||
.AddCommands(commandTypes)
|
||||
.UseVersionText(TestVersionText)
|
||||
.UseConsole(console)
|
||||
.Build();
|
||||
|
||||
@@ -166,6 +181,7 @@ namespace CliFx.Tests
|
||||
|
||||
var application = new CliApplicationBuilder()
|
||||
.AddCommands(commandTypes)
|
||||
.UseVersionText(TestVersionText)
|
||||
.UseConsole(console)
|
||||
.Build();
|
||||
|
||||
@@ -189,6 +205,7 @@ namespace CliFx.Tests
|
||||
|
||||
var application = new CliApplicationBuilder()
|
||||
.AddCommands(commandTypes)
|
||||
.UseVersionText(TestVersionText)
|
||||
.UseConsole(console)
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -92,6 +92,14 @@ namespace CliFx
|
||||
// Get schemas for all available command types
|
||||
var availableCommandSchemas = _commandSchemaResolver.GetCommandSchemas(_configuration.CommandTypes);
|
||||
|
||||
// Show version if version option was specified and command was not specified (only works on default command)
|
||||
if (commandInput.IsVersionOptionSpecified() && !commandInput.IsCommandSpecified())
|
||||
{
|
||||
_console.Output.WriteLine(_metadata.VersionText);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Find command schema matching the name specified in the input
|
||||
var targetCommandSchema = availableCommandSchemas.FindByName(commandInput.CommandName);
|
||||
|
||||
@@ -131,14 +139,6 @@ namespace CliFx
|
||||
return isError ? -1 : 0;
|
||||
}
|
||||
|
||||
// Show version if version option was specified and command was not specified (only works on default command)
|
||||
if (commandInput.IsVersionOptionSpecified() && !commandInput.IsCommandSpecified())
|
||||
{
|
||||
_console.Output.WriteLine(_metadata.VersionText);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Show help if help option was specified
|
||||
if (commandInput.IsHelpOptionSpecified())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user