Last active
January 21, 2026 20:54
-
-
Save onionhammer/92eaf6ed35e88cf4419d66f76c7d8126 to your computer and use it in GitHub Desktop.
Custom CLI commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add ReportBuilder -- Process queued reports | |
| var reportBuilder = builder | |
| .AddProject<Projects.C2C_Exchange_ReportBuilder>("c2c-exchange-reportbuilder") | |
| .WithReference(queues) | |
| .WithArgsCommand( | |
| "SendDigestDaily", | |
| "Send Daily Digest", | |
| new CommandOptions() { IconName = "CalendarMail" }, | |
| ["--digest"] | |
| ) | |
| .WithArgsCommand( | |
| "SendDigestWeekly", | |
| "Send Weekly Digest", | |
| new CommandOptions() { IconName = "CalendarMail" }, | |
| ["--digest", "--weekly"] | |
| ) | |
| .WithArgsCommand("ProcessReports", "Process Reports", new CommandOptions() { IconName = "DocumentQueue" }, []) | |
| .WithExplicitStart(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.Extensions.DependencyInjection; | |
| internal static class CommandArgsExtensions | |
| { | |
| public static IResourceBuilder<ProjectResource> WithArgsCommand( | |
| this IResourceBuilder<ProjectResource> builder, | |
| string name, | |
| string displayName, | |
| CommandOptions options, | |
| string[] args | |
| ) | |
| { | |
| options.UpdateState = OnUpdateResourceState; | |
| builder.WithCommand( | |
| name: name, | |
| displayName: displayName, | |
| commandOptions: options, | |
| executeCommand: context => OnRunCommandAsync(builder, context, args) | |
| ); | |
| return builder; | |
| } | |
| private static async Task<ExecuteCommandResult> OnRunCommandAsync( | |
| IResourceBuilder<ProjectResource> builder, | |
| ExecuteCommandContext context, | |
| string[] args | |
| ) | |
| { | |
| var commandService = context.ServiceProvider.GetRequiredService<ResourceCommandService>(); | |
| builder.WithArgs(context => | |
| { | |
| context.Args.Clear(); | |
| foreach (var arg in args) | |
| { | |
| context.Args.Add(arg); | |
| } | |
| }); | |
| return await commandService.ExecuteCommandAsync(context.ResourceName, "resource-restart"); | |
| } | |
| private static ResourceCommandState OnUpdateResourceState(UpdateCommandStateContext context) | |
| { | |
| return ResourceCommandState.Enabled; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment