Skip to content

Commit

Permalink
feat: custom commands area
Browse files Browse the repository at this point in the history
  • Loading branch information
the-avid-engineer committed Jul 25, 2024
1 parent f0d8303 commit e0e6cf8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/InfrastructureCli/Commands/CustomCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.CommandLine;

namespace InfrastructureCli.Commands;

internal record CustomCommand : CommandBase
{
public static void Attach(RootCommand rootCommand, IEnumerable<IChildCommand> 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);
}
}
5 changes: 5 additions & 0 deletions src/InfrastructureCli/Commands/ProgramCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/InfrastructureCli/Commands/ProgramCommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace InfrastructureCli.Commands;
public record ProgramCommandOptions
{
public IChildCommand[] GenerateCommands { get; init; } = Array.Empty<IChildCommand>();
public IChildCommand[] CustomCommands { get; init; } = Array.Empty<IChildCommand>();
public IValidateConfigurationsFile? ValidateConfigurationsFile { get; init; }
}

0 comments on commit e0e6cf8

Please sign in to comment.