diff --git a/src/PatchLight.Cli/CliApp.cs b/src/PatchLight.Cli/CliApp.cs index 17005e8..9fd168c 100644 --- a/src/PatchLight.Cli/CliApp.cs +++ b/src/PatchLight.Cli/CliApp.cs @@ -21,6 +21,12 @@ public static async Task RunAsync(string[] args) return 0; } + if (command == "--version") + { + Render.Version(console); + return 0; + } + var windows = SystemInfo.Read(); if (!windows.IsWindows11 || windows.DisplayVersion is null) throw new PatchLightException("PatchLight works on Windows 11 only for now."); diff --git a/src/PatchLight.Cli/CliArgs.cs b/src/PatchLight.Cli/CliArgs.cs index 388e5fb..e7a9ae3 100644 --- a/src/PatchLight.Cli/CliArgs.cs +++ b/src/PatchLight.Cli/CliArgs.cs @@ -11,7 +11,7 @@ public static string Command(string[] args) { if (args.Length == 0) return "check"; var first = args[0].ToLowerInvariant(); - if (first is "--help" or "-h" or "/?") return first; + if (first is "--help" or "-h" or "/?" or "--version") return first; return first.StartsWith('-') ? "check" : first; } diff --git a/src/PatchLight.Cli/Render.cs b/src/PatchLight.Cli/Render.cs index 9259e23..ec21d92 100644 --- a/src/PatchLight.Cli/Render.cs +++ b/src/PatchLight.Cli/Render.cs @@ -1,3 +1,4 @@ +using System.Reflection; using PatchLight.Core; using Spectre.Console; @@ -136,10 +137,20 @@ public static void Help(IAnsiConsole console) console.MarkupLine(" [bold]patchlight history[/] Recent updates and which one likely broke something"); console.MarkupLine(" [bold]patchlight uninstall KB5124008[/] Remove an installed update and keep it paused until it's fixed"); console.MarkupLine(" [bold]patchlight --no-news[/] Check without reading tech news sites"); + console.MarkupLine(" [bold]patchlight --version[/] Show the installed PatchLight version"); console.WriteLine(); console.MarkupLine("[grey]Pausing, resuming and removing need a terminal opened as administrator.[/]"); } + public static void Version(IAnsiConsole console) + { + var assembly = typeof(CliApp).Assembly; + var version = assembly.GetCustomAttribute()?.InformationalVersion + ?? assembly.GetName().Version?.ToString(3) + ?? "unknown"; + console.MarkupLine($"PatchLight {Markup.Escape(version)}"); + } + private static string Why(ReleaseReason reason) => reason switch { ReleaseReason.Fixed => "Microsoft fixed its known problems", diff --git a/tests/PatchLight.Tests/CliArgsTests.cs b/tests/PatchLight.Tests/CliArgsTests.cs index de985e7..c6f2afe 100644 --- a/tests/PatchLight.Tests/CliArgsTests.cs +++ b/tests/PatchLight.Tests/CliArgsTests.cs @@ -50,6 +50,7 @@ public void Days_rejects_absurdly_long_periods(string value) [InlineData(new[] { "--no-news" }, "check")] [InlineData(new[] { "hold", "KB5127648" }, "hold")] [InlineData(new[] { "--help" }, "--help")] + [InlineData(new[] { "--version" }, "--version")] public void Command_defaults_to_check_when_only_options_are_given(string[] args, string command) => Assert.Equal(command, CliArgs.Command(args)); } diff --git a/tests/PatchLight.Tests/RenderTests.cs b/tests/PatchLight.Tests/RenderTests.cs index adcf9d2..0313ab8 100644 --- a/tests/PatchLight.Tests/RenderTests.cs +++ b/tests/PatchLight.Tests/RenderTests.cs @@ -26,6 +26,13 @@ private static string Output(Action render) return console.Output; } + [Fact] + public void Version_shows_the_product_and_build_version() + { + var text = Output(Render.Version); + Assert.Matches(@"^PatchLight \d+\.\d+\.\d+", text); + } + [Fact] public void Red_update_shows_the_problem_and_how_to_pause_it() {