From e0e6cf872024dc47f4f3c64fc8861b147674695c Mon Sep 17 00:00:00 2001 From: Chris Philips Date: Wed, 24 Jul 2024 21:34:34 -0700 Subject: [PATCH] feat: custom commands area --- .../Commands/CustomCommand.cs | 21 +++++++++++++++++++ .../Commands/ProgramCommand.cs | 5 +++++ .../Commands/ProgramCommandOptions.cs | 1 + 3 files changed, 27 insertions(+) create mode 100644 src/InfrastructureCli/Commands/CustomCommand.cs diff --git a/src/InfrastructureCli/Commands/CustomCommand.cs b/src/InfrastructureCli/Commands/CustomCommand.cs new file mode 100644 index 0000000..17ba0a6 --- /dev/null +++ b/src/InfrastructureCli/Commands/CustomCommand.cs @@ -0,0 +1,21 @@ +using System.CommandLine; + +namespace InfrastructureCli.Commands; + +internal record CustomCommand : CommandBase +{ + public static void Attach(RootCommand rootCommand, IEnumerable childCommands) + { + var customCommand = new Command("custom") + { + Description = "Custom behavior that doesn't fall neatly into other behavior categories." + }; + + foreach (var command in childCommands) + { + command.Attach(customCommand); + } + + rootCommand.AddCommand(customCommand); + } +} \ No newline at end of file diff --git a/src/InfrastructureCli/Commands/ProgramCommand.cs b/src/InfrastructureCli/Commands/ProgramCommand.cs index b374c4f..d6a404f 100644 --- a/src/InfrastructureCli/Commands/ProgramCommand.cs +++ b/src/InfrastructureCli/Commands/ProgramCommand.cs @@ -24,6 +24,11 @@ public ProgramCommand(ProgramCommandOptions options) NewCommand.Attach(rootCommand, options.GenerateCommands); } + if (options.CustomCommands is { Length: > 0 }) + { + CustomCommand.Attach(rootCommand, options.CustomCommands); + } + _rootCommand = rootCommand; } diff --git a/src/InfrastructureCli/Commands/ProgramCommandOptions.cs b/src/InfrastructureCli/Commands/ProgramCommandOptions.cs index 726165c..d385eb4 100644 --- a/src/InfrastructureCli/Commands/ProgramCommandOptions.cs +++ b/src/InfrastructureCli/Commands/ProgramCommandOptions.cs @@ -3,5 +3,6 @@ namespace InfrastructureCli.Commands; public record ProgramCommandOptions { public IChildCommand[] GenerateCommands { get; init; } = Array.Empty(); + public IChildCommand[] CustomCommands { get; init; } = Array.Empty(); public IValidateConfigurationsFile? ValidateConfigurationsFile { get; init; } } \ No newline at end of file