Git Requirement Check

This commit is contained in:
Canon
2026-02-04 13:54:25 +08:00
parent 93e3ba8175
commit 820ca652a9
2 changed files with 53 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
using CliWrap;
using CliWrap.Buffered;
using Spectre.Console;
using Spectre.Console.Cli;
namespace FCPModUpdater.Commands;
public sealed class GitRequiredInterceptor : ICommandInterceptor
{
public void Intercept(CommandContext context, CommandSettings settings)
{
if (IsGitInstalled()) return;
// It wasn't installed..
AnsiConsole.MarkupLine("[yellow]This application requires Git to manage mods.[/]");
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine("Install Git from: [link]https://git-scm.com/downloads[/]");
throw new GitNotFoundException();
}
private static bool IsGitInstalled()
{
try
{
var result = Cli.Wrap("git")
.WithArguments("--version")
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync()
.GetAwaiter()
.GetResult();
return result.ExitCode == 0;
}
catch
{
return false;
}
}
}
public class GitNotFoundException : Exception
{
public GitNotFoundException()
: base("Git is not installed or not found in PATH.") { }
public GitNotFoundException(string message)
: base(message) { }
public GitNotFoundException(string message, Exception inner)
: base(message, inner) { }
}
+1
View File
@@ -9,6 +9,7 @@ app.Configure(config =>
{
config.SetApplicationName("fcp-mod-manager");
config.SetApplicationVersion("1.0.0");
config.SetInterceptor(new GitRequiredInterceptor());
config.AddCommand<ScanCommand>("scan")
.WithDescription("Scan mods and show interactive menu (DEFAULT)")