Skip to content

Commit

Permalink
simplify config model bump to 2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lineville committed Oct 11, 2023
1 parent 69cece7 commit 971de65
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 55 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@ jobs:
run: |
dotnet test
# TODO mongo password not getting embedded properly some commands fail
- name: 🔏 Configure Secrets
uses: microsoft/variable-substitution@v1
with:
files: '**/appsettings.json'
env:
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}

- name: 📦 Build
working-directory: ./USTACLI
env:
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
run: dotnet pack -c Release

- name: 🚀 Publish to Nuget
working-directory: ./USTACLI
env:
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
run: dotnet nuget push ./nupkg/*.nupkg -n -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json

- name: 🚀 Publish to GitHub
working-directory: ./USTACLI
env:
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
run: dotnet nuget push ./nupkg/*.nupkg -n -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/lineville/index.json
5 changes: 3 additions & 2 deletions USTACLI.Tests/appsettings.Test.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"Gender": "ntrp-rankListGender",
"Level": "ntrp-ntrpPlayerLevel",
"Section": "ntrp-sectionCode"
}
}
},
"MONGO_PASSWORD": ""
}
28 changes: 19 additions & 9 deletions USTACLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Spectre.Console.Cli;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Spectre.Console.Cli;

public class Program
{
Expand All @@ -9,17 +11,25 @@ public static int Main(string[] args)
{
// Parse command line arguments
var app = new CommandApp();

// Load appsettings.json static data
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Directory.GetCurrentDirectory();

IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(assemblyFolder)
.AddJsonFile("appsettings.json", optional: false)
.AddEnvironmentVariables()
.Build();

app.Configure(config =>
{
config.AddCommand<GetRankingsCommand>("get");
config.AddCommand<ListRankingsCommand>("list");
config.AddCommand<SubscribeRankingsCommand>("subscribe");
config.AddCommand<UnsubscribeRankingsCommand>("unsubscribe");
config.AddCommand<GetRankingsCommand>("get").WithDescription("Get player ranking").WithData(configuration);
config.AddCommand<ListRankingsCommand>("list").WithDescription("List player rankings").WithData(configuration);
config.AddCommand<SubscribeRankingsCommand>("subscribe").WithDescription("Subscribe to player rankings").WithData(configuration);
config.AddCommand<UnsubscribeRankingsCommand>("unsubscribe").WithDescription("Unsubscribe from player rankings").WithData(configuration);

config.AddBranch("subscribers", subscribers =>
{
subscribers.AddCommand<ListSubscribersCommand>("list");
});
// Hidden command used by GH actions (not intended for end user usage)
config.AddCommand<ListSubscribersCommand>("subscribers").WithData(configuration).IsHidden();
});

return app.Run(args);
Expand Down
5 changes: 3 additions & 2 deletions USTACLI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"Gender": "ntrp-rankListGender",
"Level": "ntrp-ntrpPlayerLevel",
"Section": "ntrp-sectionCode"
}
}
},
"MONGO_PASSWORD": ""
}
13 changes: 5 additions & 8 deletions USTACLI/cli/GetRankingsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

public class GetRankingsCommand : Command<RankingsSettings>
{
#nullable disable
#nullable disable
public override int Execute(CommandContext context, RankingsSettings settings)
{
#nullable enable
// Load appsettings.json static data
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.Build();
#nullable enable
var configuration = context.Data as IConfiguration
?? throw new Exception("Failed to load configuration from appsettings.json");

Utilities.InteractiveFallback(settings, configuration, context.Name);

Expand Down Expand Up @@ -75,7 +72,7 @@ public RankingsReport ScrapePlayerRanking(WebDriver driver, IConfiguration confi
var timeout = configuration.GetValue<int>("PAGE_LOAD_TIMEOUT");

var url = Utilities.BuildUSTARankingURL(settings, configuration, context);

// Navigate to the URL and wait for the page to load
driver.Navigate().GoToUrl(url);
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
Expand Down
8 changes: 2 additions & 6 deletions USTACLI/cli/ListRankingsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ public class ListRankingsCommand : Command<RankingsSettings>
public override int Execute(CommandContext context, RankingsSettings settings)
{
#nullable enable

// Load appsettings.json static data
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.Build();
var configuration = context.Data as IConfiguration
?? throw new Exception("Failed to load configuration from appsettings.json");

Utilities.InteractiveFallback(settings, configuration, context.Name);

Expand Down
8 changes: 2 additions & 6 deletions USTACLI/cli/ListSubscribersCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ public class ListSubscribersCommand : Command
public override int Execute(CommandContext context)
{
#nullable enable
// Load appsettings.json static data
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.AddEnvironmentVariables()
.Build();
var configuration = context.Data as IConfiguration
?? throw new Exception("Failed to load configuration from appsettings.json");

GetSubscribers(configuration).GetAwaiter().GetResult();
return 0;
Expand Down
8 changes: 2 additions & 6 deletions USTACLI/cli/SubscribeRankingsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ public class SubscribeRankingsCommand : Spectre.Console.Cli.Command<RankingsSett
public override int Execute(CommandContext context, RankingsSettings settings)
{
#nullable enable
// Load appsettings.json static data
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.AddEnvironmentVariables()
.Build();
var configuration = context.Data as IConfiguration
?? throw new Exception("Failed to load configuration from appsettings.json");

Utilities.InteractiveFallback(settings, configuration, context.Name);

Expand Down
8 changes: 2 additions & 6 deletions USTACLI/cli/UnsubscribeRankingsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ public class UnsubscribeRankingsCommand : Spectre.Console.Cli.Command<RankingsSe
public override int Execute(CommandContext context, RankingsSettings settings)
{
#nullable enable
// Load appsettings.json static data
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.AddEnvironmentVariables()
.Build();
var configuration = context.Data as IConfiguration
?? throw new Exception("Failed to load configuration from appsettings.json");

Utilities.InteractiveFallback(settings, configuration, context.Name);

Expand Down
2 changes: 1 addition & 1 deletion USTACLI/cli/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.Configuration;
using Spectre.Console;

public class Utilities
public static class Utilities
{

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion USTACLI/usta-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ToolCommandName>usta-cli</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>2.0.3</PackageVersion>
<PackageVersion>2.0.4</PackageVersion>
<RepositoryUrl>https://github.com/lineville/usta-cli</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"Gender": "ntrp-rankListGender",
"Level": "ntrp-ntrpPlayerLevel",
"Section": "ntrp-sectionCode"
}
},
"MONGO_PASSWORD": ""
}

0 comments on commit 971de65

Please sign in to comment.