Skip to content

Commit

Permalink
Merge pull request #2550 from wabbajack-tools/set-nexus-api-key
Browse files Browse the repository at this point in the history
Add 'set-nexus-api-key' CLI command
  • Loading branch information
EzioTheDeadPoet authored May 25, 2024
2 parents f69088e + fd01fad commit a5d9bea
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
### Changelog

#### Version - 3.6.1.0 - TBD
* Added `set-nexus-api-key` CLI command
* Added Starfield meta data
* Added Fallout New Vegas Epic Games meta data

#### Version - 3.6.0.0 - 5/25/2024
* Wabbajack now uses OAuth2 for Nexus Mods logins
Expand Down
19 changes: 19 additions & 0 deletions Wabbajack.CLI/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions Wabbajack.CLI/VerbRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static void AddCLIVerbs(this IServiceCollection services) {
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);
Expand Down
46 changes: 46 additions & 0 deletions Wabbajack.CLI/Verbs/SetNexusApiKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

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 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;
}
}
}
3 changes: 2 additions & 1 deletion Wabbajack.CLI/Wabbajack.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<Version>$(VERSION)</Version>
<AssemblyName>wabbajack-cli</AssemblyName>
<PublishTrimmed>true</PublishTrimmed>
<PublishTrimmed>false</PublishTrimmed>
<TimeMode>linked</TimeMode>
<NoWarn>CS8600</NoWarn>
<NoWarn>CS8601</NoWarn>
<NoWarn>CS8618</NoWarn>
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit a5d9bea

Please sign in to comment.