Add set-nexus-api-key command

This commit is contained in:
trawzified 2024-05-16 18:52:33 +02:00
parent 1cec66d6fe
commit 6db4fd0737
4 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0-windows\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>
</Project>

View File

@ -43,6 +43,8 @@ CommandLineBuilder.RegisterCommand<MirrorFile>(MirrorFile.Definition, c => ((Mir
services.AddSingleton<MirrorFile>();
CommandLineBuilder.RegisterCommand<ModlistReport>(ModlistReport.Definition, c => ((ModlistReport)c).Run);
services.AddSingleton<ModlistReport>();
CommandLineBuilder.RegisterCommand<SetNexusApiKey>(SetNexusApiKey.Definition, c => ((SetNexusApiKey)c).Run);
services.AddSingleton<SetNexusApiKey>();
CommandLineBuilder.RegisterCommand<SteamDownloadFile>(SteamDownloadFile.Definition, c => ((SteamDownloadFile)c).Run);
services.AddSingleton<SteamDownloadFile>();
CommandLineBuilder.RegisterCommand<SteamDumpAppInfo>(SteamDumpAppInfo.Definition, c => ((SteamDumpAppInfo)c).Run);

View File

@ -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<NexusApiState> _tokenProvider;
private readonly ILogger<SetNexusApiKey> _logger;
public SetNexusApiKey(EncryptedJsonTokenProvider<NexusApiState> tokenProvider, ILogger<SetNexusApiKey> 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<int> 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;
}
}
}

View File

@ -14,6 +14,7 @@
<NoWarn>CS8601</NoWarn>
<NoWarn>CS8618</NoWarn>
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>