diff --git a/Commands/ScanCommand.cs b/Commands/ScanCommand.cs index 16ed6f5..ff0108d 100644 --- a/Commands/ScanCommand.cs +++ b/Commands/ScanCommand.cs @@ -1,30 +1,30 @@ using FCPModUpdater.Commands.Settings; using FCPModUpdater.Services; using FCPModUpdater.UI; +using JetBrains.Annotations; using Spectre.Console; using Spectre.Console.Cli; namespace FCPModUpdater.Commands; +[UsedImplicitly] public class ScanCommand( IGitService gitService, IGitHubApiService gitHubApiService, IModDiscoveryService modDiscoveryService, UpdateCheckService updateCheckService) : AsyncCommand { - public override async Task ExecuteAsync(CommandContext context, ModPathSettings settings, + protected override async Task ExecuteAsync(CommandContext context, ModPathSettings settings, CancellationToken cancellationToken) { try { var modsDirectory = ModsDirectoryResolver.Resolve(settings.ModDirectory?.FullName, interactive: true); - if (modsDirectory == null) - return 1; AnsiConsole.MarkupLine($"[grey]Using mods directory: {modsDirectory}[/]"); AnsiConsole.WriteLine(); - var updateCheckTask = updateCheckService.CheckForUpdateAsync(cancellationToken); + Task updateCheckTask = updateCheckService.CheckForUpdateAsync(cancellationToken); var menu = new InteractiveMenu( gitService, diff --git a/Commands/UpdateCommand.cs b/Commands/UpdateCommand.cs index f1cf23f..77c0029 100644 --- a/Commands/UpdateCommand.cs +++ b/Commands/UpdateCommand.cs @@ -17,23 +17,21 @@ public class UpdateCommand( public static IReadOnlyList GetUpdateableMods(IReadOnlyList mods) => mods.Where(m => m.Source == ModSource.Git && m.Status == ModStatus.Behind).ToList(); - public override async Task ExecuteAsync(CommandContext context, ModPathSettings settings, - CancellationToken cancellationToken) + protected override async Task ExecuteAsync(CommandContext context, ModPathSettings settings, + CancellationToken ct) { try { var modsDirectory = ModsDirectoryResolver.Resolve(settings.ModDirectory?.FullName, interactive: false); - if (modsDirectory == null) - return 1; AnsiConsole.MarkupLine($"[grey]Using mods directory: {modsDirectory}[/]"); AnsiConsole.WriteLine(); - var updateCheckTask = updateCheckService.CheckForUpdateAsync(cancellationToken); + Task updateCheckTask = updateCheckService.CheckForUpdateAsync(ct); var mods = await ProgressReporter.WithStatusAsync( "Scanning mods directory...", - async () => await modDiscoveryService.DiscoverModsAsync(modsDirectory, ct: cancellationToken)); + async () => await modDiscoveryService.DiscoverModsAsync(modsDirectory, ct: ct)); var updateableMods = GetUpdateableMods(mods); @@ -54,16 +52,16 @@ public class UpdateCommand( var results = await ProgressReporter.WithBatchProgressAsync( "Updating mods", updateableMods, - m => m.Name, + installedMod => installedMod.Name, async (mod, progress) => { progress.Report(25); - var fetchOk = await gitService.FetchAsync(mod.Path, ct: cancellationToken); + var fetchOk = await gitService.FetchAsync(mod.Path, ct: ct); if (!fetchOk) return (false, "Fetch failed"); progress.Report(50); - var pullOk = await gitService.PullAsync(mod.Path, ct: cancellationToken); + var pullOk = await gitService.PullAsync(mod.Path, ct: ct); progress.Report(100); return (pullOk, pullOk ? null : "Pull failed"); @@ -71,7 +69,7 @@ public class UpdateCommand( ModTableRenderer.RenderUpdateSummary(results); - var updateResult = await updateCheckTask; + UpdateCheckResult? updateResult = await updateCheckTask; if (updateResult != null) { AnsiConsole.WriteLine(); diff --git a/FCPModUpdater.csproj b/FCPModUpdater.csproj index 68065e9..9aa4f9c 100644 --- a/FCPModUpdater.csproj +++ b/FCPModUpdater.csproj @@ -23,8 +23,8 @@ - - + + diff --git a/packages.lock.json b/packages.lock.json index fa60c66..d827927 100644 --- a/packages.lock.json +++ b/packages.lock.json @@ -39,17 +39,20 @@ }, "Spectre.Console": { "type": "Direct", - "requested": "[0.54.0, )", - "resolved": "0.54.0", - "contentHash": "StDXCFayfy0yB1xzUHT2tgEpV1/HFTiS4JgsAQS49EYTfMixSwwucaQs/bIOCwXjWwIQTMuxjUIxcB5XsJkFJA==" + "requested": "[0.55.0, )", + "resolved": "0.55.0", + "contentHash": "2TVhUHFsDux0Z+y2Hv4bFsOMuON4SuotEEKkMparFkp5Rm259naaaEQrN4Sv6C1cbsiGKPjfkJDGgUp+hZPjTw==", + "dependencies": { + "Spectre.Console.Ansi": "0.55.0" + } }, "Spectre.Console.Cli": { "type": "Direct", - "requested": "[0.53.1, )", - "resolved": "0.53.1", - "contentHash": "y//7ZZ0shhvgXzoJXJzMaLGA4dPem8qCbkyv9khfE8NQDlH4hPVsHOHYoz6uzAwiTX9Yd7OnX3wNOX/wRfPUOg==", + "requested": "[0.55.0, )", + "resolved": "0.55.0", + "contentHash": "cFJTB1te4eaAICd4Zp+8T/kiRn1ikQxgGqmoNarb1qoQ/7LzHAvVQ62x5U9GW3E0QI7sZLcXIIoq4CpqgTx42Q==", "dependencies": { - "Spectre.Console": "0.53.1" + "Spectre.Console": "0.55.0" } }, "Microsoft.Extensions.Configuration": { @@ -145,6 +148,11 @@ "type": "Transitive", "resolved": "10.0.5", "contentHash": "/HUHJ0tw/LQvD0DZrz50eQy/3z7PfX7WWEaXnjKTV9/TNdcgFlNTZGo49QhS7PTmhDqMyHRMqAXSBxLh0vso4g==" + }, + "Spectre.Console.Ansi": { + "type": "Transitive", + "resolved": "0.55.0", + "contentHash": "GIfgOvuF8MpU52bprhwtDEtx0gmVIGOepM8bw0lH/TSMD0rg1Xp+5Y53kPG8rFVdcpbNANlhDQ5mEVVPO3/2Tg==" } } }