feat: Dynamic command loader, default command with module registry
This commit is contained in:
34
Commands/Image/BuildCommand.cs
Normal file
34
Commands/Image/BuildCommand.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.ComponentModel;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Automancer.Command.Image;
|
||||
|
||||
public class BuldSettings: CommandSettings
|
||||
{
|
||||
[CommandArgument(0, "[path]")]
|
||||
[Description("Path to the Dockerfile")]
|
||||
public string? Path { get; set; }
|
||||
|
||||
[CommandOption("-t|--tag")]
|
||||
[Description("Tag to use for the image")]
|
||||
public string? Tag { get; set; }
|
||||
|
||||
[CommandOption("-f|--file")]
|
||||
[Description("Path to the Dockerfile")]
|
||||
public string? File { get; set; }
|
||||
|
||||
[CommandOption("--push")]
|
||||
[Description("Push the image after building it")]
|
||||
public bool Push { get; set; }
|
||||
}
|
||||
|
||||
public class BuildCommand : Command<BuldSettings>
|
||||
{
|
||||
public override int Execute(CommandContext context, BuldSettings settings)
|
||||
{
|
||||
Console.WriteLine($"Building image from {settings.Path} with tag {settings.Tag}");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
25
Commands/Image/Module.cs
Normal file
25
Commands/Image/Module.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Automancer.Common;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Automancer.Command.Image;
|
||||
|
||||
public class Module : ICommandModuleWithRegistry
|
||||
{
|
||||
public void Configure(IConfigurator config)
|
||||
{
|
||||
// No implementation needed here
|
||||
}
|
||||
public void Configure(IConfigurator config, CommandRegistry registry)
|
||||
{
|
||||
config.AddBranch("image", image => {
|
||||
var description = "Docker/podman image operations";
|
||||
image.SetDescription(description);
|
||||
registry.Add("image", description);
|
||||
|
||||
image.AddCommand<BuildCommand>("build").WithDescription("Build a docker image");
|
||||
image.AddCommand<PushCommand>("push").WithDescription("Push a docker image");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
30
Commands/Image/PushCommand.cs
Normal file
30
Commands/Image/PushCommand.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.ComponentModel;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Automancer.Command.Image;
|
||||
|
||||
public class PushSettings: CommandSettings
|
||||
{
|
||||
[CommandArgument(0, "[path]")]
|
||||
[Description("Path to the Dockerfile")]
|
||||
public string? Path { get; set; }
|
||||
|
||||
[CommandOption("-t|--tag")]
|
||||
[Description("Tag to use for the image")]
|
||||
public string? Tag { get; set; }
|
||||
|
||||
[CommandOption("-f|--file")]
|
||||
[Description("Path to the Dockerfile")]
|
||||
public string? File { get; set; }
|
||||
}
|
||||
|
||||
public class PushCommand : Command<BuldSettings>
|
||||
{
|
||||
public override int Execute(CommandContext context, BuldSettings settings)
|
||||
{
|
||||
Console.WriteLine($"Building image from {settings.Path} with tag {settings.Tag}");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user