Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotnet-openai/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#endif

// --quiet does not report sponsor tier on every run.
((IServiceProvider)registrar).GetRequiredService<CheckCommand>().Execute(
await ((IServiceProvider)registrar).GetRequiredService<CheckCommand>().ExecuteAsync(
new CommandContext(["--quiet"], RemainingArguments.Empty, "check", null),
new CheckCommand.CheckSettings { Quiet = true });

Expand Down
27 changes: 19 additions & 8 deletions src/dotnet-openai/Sponsors/CheckCommand.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using System.ComponentModel;
using Devlooped.Sponsors;
using DotNetConfig;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console;
using Spectre.Console.Cli;
using static Devlooped.OpenAI.Sponsors.CheckCommand;
using static ThisAssembly.Strings;

namespace Devlooped.OpenAI.Sponsors;

[Description("Checks the current sponsorship status with [lime]devlooped[/], entirely offline")]
[Service]
public class CheckCommand(IAnsiConsole console) : Command<CheckSettings>
public class CheckCommand(Config config, Lazy<DevloopedSyncCommand> sync, IAnsiConsole console) : AsyncCommand<CheckSettings>
{
public class CheckSettings : CommandSettings
{
[CommandOption("-q|--quiet", IsHidden = true)]
public bool Quiet { get; set; }
}

public override int Execute(CommandContext context, CheckSettings settings)
public override async Task<int> ExecuteAsync(CommandContext context, CheckSettings settings)
{
// Don't render anything if not interactive, so we don't disrupt usage in CI for example.
// In GH actions, console input/output is redirected, for example, and output is redirected
Expand All @@ -34,37 +36,46 @@ public override int Execute(CommandContext context, CheckSettings settings)
var link = "[link=https://github.com/devlooped/#sponsorlink]devlooped[/]";

if (!System.IO.File.Exists(jwtPath))
return MarkupLine(ThisAssembly.Strings.Unknown.Message(project, link));
return MarkupLine(Unknown.Message(project, link));

var manifest = SponsorLink.GetManifest("devlooped", ThisAssembly.Metadata.Funding.GitHub.devlooped, true);
if (manifest.Status == ManifestStatus.Valid)
return 0;

// If not valid and we can auto-sync, do it now.
if (config.GetBoolean("sponsorlink", "autosync") == true)
{
await sync.Value.ExecuteAsync(context, new() { Unattended = settings.Quiet });
manifest = SponsorLink.GetManifest("devlooped", ThisAssembly.Metadata.Funding.GitHub.devlooped, true);
if (manifest.Status == ManifestStatus.Valid)
return 0;
}

if (manifest.Status == ManifestStatus.Unknown || manifest.Status == ManifestStatus.Invalid)
return MarkupLine(ThisAssembly.Strings.Unknown.Message(project, link));
return MarkupLine(Unknown.Message(project, link));

if (manifest.Status == ManifestStatus.Expired)
return MarkupLine(ThisAssembly.Strings.Expired.Message);
return MarkupLine(Expired.Message);

if (settings.Quiet)
return 0;

if (manifest.Principal.IsInRole("team"))
return MarkupLine(ThisAssembly.Strings.Team.Message(link));
return MarkupLine(Team.Message(link));

if (manifest.Principal.IsInRole("user"))
return MarkupLine(ThisAssembly.Strings.Sponsor.Message(project));

if (manifest.Principal.IsInRole("contrib"))
return MarkupLine(ThisAssembly.Strings.Contributor.Message(link));
return MarkupLine(Contributor.Message(link));

if (manifest.Principal.IsInRole("org"))
return MarkupLine(ThisAssembly.Strings.Sponsor.Message(project));

if (manifest.Principal.IsInRole("oss"))
return MarkupLine(ThisAssembly.Strings.OpenSource.Message);

return MarkupLine(ThisAssembly.Strings.Unknown.Message(project, link));
return MarkupLine(Unknown.Message(project, link));
}

int MarkupLine(string message)
Expand Down
4 changes: 3 additions & 1 deletion src/dotnet-openai/Sponsors/SyncCommand.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.ComponentModel;
using Devlooped.Sponsors;
using DotNetConfig;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;

namespace Devlooped.OpenAI.Sponsors;

[Description("Synchronizes your sponsorship manifest for [lime]devlooped[/]")]
class DevloopedSyncCommand(Config config, IGraphQueryClient client, IGitHubAppAuthenticator authenticator, IHttpClientFactory httpFactory)
[Service]
public class DevloopedSyncCommand(Config config, IGraphQueryClient client, IGitHubAppAuthenticator authenticator, IHttpClientFactory httpFactory)
: SyncCommand<DevloopedSyncCommand.DevloopedSyncSettings>(config, client, authenticator, httpFactory)
{
public class DevloopedSyncSettings : SyncSettings, ISponsorableSettings
Expand Down