Make -v|--version opt-in

We added an automatic version option in 0.49. We did this with good
intentions, but forgot that people might already use --version
as an option for a root command.

This commit makes -v|--version completely opt-in.
This commit is contained in:
Patrik Svensson
2024-04-25 19:34:07 +02:00
committed by Patrik Svensson
parent 88515b7d7f
commit 3acc90e47c
36 changed files with 276 additions and 211 deletions

View File

@ -39,9 +39,12 @@ internal sealed class CommandExecutor
if (firstArgument.Equals("--version", StringComparison.OrdinalIgnoreCase) ||
firstArgument.Equals("-v", StringComparison.OrdinalIgnoreCase))
{
var console = configuration.Settings.Console.GetConsole();
console.WriteLine(ResolveApplicationVersion(configuration));
return 0;
if (configuration.Settings.ApplicationVersion != null)
{
var console = configuration.Settings.Console.GetConsole();
console.MarkupLine(configuration.Settings.ApplicationVersion);
return 0;
}
}
}
}
@ -126,13 +129,6 @@ internal sealed class CommandExecutor
return parsedResult;
}
private static string ResolveApplicationVersion(IConfiguration configuration)
{
return
configuration.Settings.ApplicationVersion ?? // potential override
VersionHelper.GetVersion(Assembly.GetEntryAssembly());
}
private static async Task<int> Execute(
CommandTree leaf,
CommandTree tree,

View File

@ -3,6 +3,7 @@ namespace Spectre.Console.Cli;
internal sealed class CommandModel : ICommandContainer, ICommandModel
{
public string? ApplicationName { get; }
public string? ApplicationVersion { get; }
public ParsingMode ParsingMode { get; }
public IList<CommandInfo> Commands { get; }
public IList<string[]> Examples { get; }
@ -20,9 +21,10 @@ internal sealed class CommandModel : ICommandContainer, ICommandModel
IEnumerable<string[]> examples)
{
ApplicationName = settings.ApplicationName;
ApplicationVersion = settings.ApplicationVersion;
ParsingMode = settings.ParsingMode;
Commands = new List<CommandInfo>(commands ?? Array.Empty<CommandInfo>());
Examples = new List<string[]>(examples ?? Array.Empty<string[]>());
Commands = new List<CommandInfo>(commands);
Examples = new List<string[]>(examples);
}
/// <summary>