feat: Dynamic command loader, default command with module registry
This commit is contained in:
		
							
								
								
									
										26
									
								
								Commands/Container/Module.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Commands/Container/Module.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
using Automancer.Command.Image;
 | 
			
		||||
using Automancer.Common;
 | 
			
		||||
using Spectre.Console.Cli;
 | 
			
		||||
 | 
			
		||||
namespace Automancer.Command.Container;
 | 
			
		||||
 | 
			
		||||
public class Module : ICommandModuleWithRegistry
 | 
			
		||||
{
 | 
			
		||||
    public void Configure(IConfigurator config)
 | 
			
		||||
    {
 | 
			
		||||
        // No implementation needed here
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Configure(IConfigurator config, CommandRegistry registry)
 | 
			
		||||
    {
 | 
			
		||||
        config.AddBranch("container", container =>
 | 
			
		||||
        {
 | 
			
		||||
            var description = "Container operations";
 | 
			
		||||
            
 | 
			
		||||
            container.SetDescription(description);
 | 
			
		||||
            registry.Add("container", description);
 | 
			
		||||
 | 
			
		||||
            container.AddCommand<PsCommand>("ps").WithDescription("List containers");
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								Commands/Container/PsCommand.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								Commands/Container/PsCommand.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using Spectre.Console.Cli;
 | 
			
		||||
 | 
			
		||||
namespace Automancer.Command.Image;
 | 
			
		||||
 | 
			
		||||
public class PsSettings: 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 PsCommand: 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