From 6db4fd0737fda0988bb94a02aca34a0b7dc332e5 Mon Sep 17 00:00:00 2001 From: trawzified <55751269+tr4wzified@users.noreply.github.com> Date: Thu, 16 May 2024 18:52:33 +0200 Subject: [PATCH] Add set-nexus-api-key command --- .../PublishProfiles/FolderProfile.pubxml | 18 +++++++ Wabbajack.CLI/VerbRegistration.cs | 2 + Wabbajack.CLI/Verbs/SetNexusApiKey.cs | 47 +++++++++++++++++++ Wabbajack.CLI/Wabbajack.CLI.csproj | 1 + 4 files changed, 68 insertions(+) create mode 100644 Wabbajack.CLI/Properties/PublishProfiles/FolderProfile.pubxml create mode 100644 Wabbajack.CLI/Verbs/SetNexusApiKey.cs diff --git a/Wabbajack.CLI/Properties/PublishProfiles/FolderProfile.pubxml b/Wabbajack.CLI/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 00000000..57b24e02 --- /dev/null +++ b/Wabbajack.CLI/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,18 @@ + + + + + Release + Any CPU + bin\Release\net8.0-windows\publish\ + FileSystem + <_TargetId>Folder + net8.0 + win-x64 + true + false + false + + \ No newline at end of file diff --git a/Wabbajack.CLI/VerbRegistration.cs b/Wabbajack.CLI/VerbRegistration.cs index 3854dce4..373b4b43 100644 --- a/Wabbajack.CLI/VerbRegistration.cs +++ b/Wabbajack.CLI/VerbRegistration.cs @@ -43,6 +43,8 @@ CommandLineBuilder.RegisterCommand(MirrorFile.Definition, c => ((Mir services.AddSingleton(); CommandLineBuilder.RegisterCommand(ModlistReport.Definition, c => ((ModlistReport)c).Run); services.AddSingleton(); +CommandLineBuilder.RegisterCommand(SetNexusApiKey.Definition, c => ((SetNexusApiKey)c).Run); +services.AddSingleton(); CommandLineBuilder.RegisterCommand(SteamDownloadFile.Definition, c => ((SteamDownloadFile)c).Run); services.AddSingleton(); CommandLineBuilder.RegisterCommand(SteamDumpAppInfo.Definition, c => ((SteamDumpAppInfo)c).Run); diff --git a/Wabbajack.CLI/Verbs/SetNexusApiKey.cs b/Wabbajack.CLI/Verbs/SetNexusApiKey.cs new file mode 100644 index 00000000..37bf618d --- /dev/null +++ b/Wabbajack.CLI/Verbs/SetNexusApiKey.cs @@ -0,0 +1,47 @@ + +using System.CommandLine; +using System.CommandLine.Invocation; +using System.CommandLine.NamingConventionBinder; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Wabbajack.CLI.Builder; +using Wabbajack.DTOs.Logins; +using Wabbajack.Paths; +using Wabbajack.Paths.IO; +using Wabbajack.Services.OSIntegrated; + +namespace Wabbajack.CLI.Verbs; + +public class SetNexusApiKey +{ + private readonly EncryptedJsonTokenProvider _tokenProvider; + private readonly ILogger _logger; + + public SetNexusApiKey(EncryptedJsonTokenProvider tokenProvider, ILogger logger) + { + _tokenProvider = tokenProvider; + _logger = logger; + } + + public static VerbDefinition Definition = new VerbDefinition("set-nexus-api-key", + "Sets the Nexus API key to the specified value", + new[] + { + new OptionDefinition(typeof(string), "k", "key", "The Nexus API key") + }); + + public async Task Run(string key) + { + if (string.IsNullOrEmpty(key)) + { + _logger.LogInformation("Not setting Nexus API key, that looks like an empty string to me."); + return -1; + } + else + { + await _tokenProvider.SetToken(new NexusApiState { ApiKey = key }); + _logger.LogInformation("Set Nexus API Key to {key}", key); + return 0; + } + } +} \ No newline at end of file diff --git a/Wabbajack.CLI/Wabbajack.CLI.csproj b/Wabbajack.CLI/Wabbajack.CLI.csproj index 7fc4af60..4b656cf1 100644 --- a/Wabbajack.CLI/Wabbajack.CLI.csproj +++ b/Wabbajack.CLI/Wabbajack.CLI.csproj @@ -14,6 +14,7 @@ CS8601 CS8618 true + net8.0