Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/PatchLight.Cli/CliApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public static async Task<int> 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.");
Expand Down
2 changes: 1 addition & 1 deletion src/PatchLight.Cli/CliArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions src/PatchLight.Cli/Render.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Reflection;
using PatchLight.Core;
using Spectre.Console;

Expand Down Expand Up @@ -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<AssemblyInformationalVersionAttribute>()?.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",
Expand Down
1 change: 1 addition & 0 deletions tests/PatchLight.Tests/CliArgsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
7 changes: 7 additions & 0 deletions tests/PatchLight.Tests/RenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ private static string Output(Action<TestConsole> 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()
{
Expand Down