mirror of
https://github.com/FalloutCollaborationProject/FCP-Mod-Updater.git
synced 2026-07-27 17:04:05 -07:00
Git Requirement Check
This commit is contained in:
@@ -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) { }
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ app.Configure(config =>
|
|||||||
{
|
{
|
||||||
config.SetApplicationName("fcp-mod-manager");
|
config.SetApplicationName("fcp-mod-manager");
|
||||||
config.SetApplicationVersion("1.0.0");
|
config.SetApplicationVersion("1.0.0");
|
||||||
|
config.SetInterceptor(new GitRequiredInterceptor());
|
||||||
|
|
||||||
config.AddCommand<ScanCommand>("scan")
|
config.AddCommand<ScanCommand>("scan")
|
||||||
.WithDescription("Scan mods and show interactive menu (DEFAULT)")
|
.WithDescription("Scan mods and show interactive menu (DEFAULT)")
|
||||||
|
|||||||
Reference in New Issue
Block a user