| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using RackPeek.Commands;
- using RackPeek.Commands.Server;
- using RackPeek.Commands.Server.Cpus;
- using RackPeek.Commands.Server.Drives;
- using RackPeek.Commands.Server.Gpu;
- using RackPeek.Commands.Server.Nics;
- using RackPeek.Commands.Switches;
- using RackPeek.Domain.Resources.Hardware;
- using RackPeek.Domain.Resources.Hardware.Reports;
- using RackPeek.Domain.Resources.Hardware.Server;
- using RackPeek.Domain.Resources.Hardware.Server.Cpu;
- using RackPeek.Domain.Resources.Hardware.Server.Drive;
- using RackPeek.Domain.Resources.Hardware.Server.Gpu;
- using RackPeek.Domain.Resources.Hardware.Server.Nic;
- using RackPeek.Domain.Resources.Hardware.Switchs;
- using RackPeek.Spectre;
- using RackPeek.Yaml;
- using Spectre.Console.Cli;
- namespace RackPeek;
- public static class Program
- {
- public static async Task<int> Main(string[] args)
- {
- // Configuration
- var configuration = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile("appsettings.json", true)
- .Build();
- // DI
- var services = new ServiceCollection();
- var registrar = new TypeRegistrar(services);
- var app = new CommandApp(registrar);
-
- CliBootstrap.BuildApp(app, services, configuration);
-
- services.AddLogging(configure =>
- configure
- .AddSimpleConsole(opts => { opts.TimestampFormat = "yyyy-MM-dd HH:mm:ss "; }));
-
- return await app.RunAsync(args);
- }
- }
- public static class CliBootstrap
- {
- public static void BuildApp(CommandApp app, IServiceCollection services, IConfiguration configuration)
- {
- services.AddSingleton<IConfiguration>(configuration);
- // Infrastructure
- services.AddScoped<IHardwareRepository>(_ =>
- {
- var collection = new YamlResourceCollection();
- var basePath = configuration["HardwarePath"] ?? Directory.GetCurrentDirectory();
- collection.LoadFiles(new[]
- {
- Path.Combine(basePath, "servers.yaml"),
- Path.Combine(basePath, "aps.yaml"),
- Path.Combine(basePath, "desktops.yaml"),
- Path.Combine(basePath, "switches.yaml"),
- Path.Combine(basePath, "ups.yaml"),
- Path.Combine(basePath, "firewalls.yaml"),
- Path.Combine(basePath, "laptops.yaml"),
- Path.Combine(basePath, "routers.yaml")
- });
- return new YamlHardwareRepository(collection);
- });
- // Application
- services.AddScoped<ServerHardwareReportUseCase>();
- services.AddScoped<ServerReportCommand>();
- services.AddScoped<AccessPointHardwareReportUseCase>();
- services.AddScoped<AccessPointReportCommand>();
- services.AddScoped<SwitchHardwareReportUseCase>();
- services.AddScoped<SwitchReportCommand>();
- services.AddScoped<UpsHardwareReportUseCase>();
- services.AddScoped<UpsReportCommand>();
- services.AddScoped<DesktopHardwareReportUseCase>();
- services.AddScoped<DesktopReportCommand>();
- services.AddScoped<AddServerUseCase>();
- services.AddScoped<ServerAddCommand>();
- services.AddScoped<DeleteServerUseCase>();
- services.AddScoped<ServerDeleteCommand>();
- services.AddScoped<DescribeServerUseCase>();
- services.AddScoped<ServerDescribeCommand>();
- services.AddScoped<GetServerUseCase>();
- services.AddScoped<ServerGetByNameCommand>();
- services.AddScoped<UpdateServerUseCase>();
- services.AddScoped<ServerSetCommand>();
- // CPU use cases
- services.AddScoped<AddCpuUseCase>();
- services.AddScoped<UpdateCpuUseCase>();
- services.AddScoped<RemoveCpuUseCase>();
- // Drive use cases
- services.AddScoped<AddDrivesUseCase>();
- services.AddScoped<UpdateDriveUseCase>();
- services.AddScoped<RemoveDriveUseCase>();
-
- // GPU use cases
- services.AddScoped<AddGpuUseCase>();
- services.AddScoped<UpdateGpuUseCase>();
- services.AddScoped<RemoveGpuUseCase>();
- // CPU commands
- services.AddScoped<ServerCpuAddCommand>();
- services.AddScoped<ServerCpuSetCommand>();
- services.AddScoped<ServerCpuRemoveCommand>();
- // Switch commands
- services.AddScoped<SwitchAddCommand>();
- services.AddScoped<SwitchDeleteCommand>();
- services.AddScoped<SwitchDescribeCommand>();
- services.AddScoped<SwitchGetByNameCommand>();
- services.AddScoped<SwitchGetCommand>();
- services.AddScoped<SwitchSetCommand>();
- // Switch Usecases
- services.AddScoped<AddSwitchUseCase>();
- services.AddScoped<DeleteSwitchUseCase>();
- services.AddScoped<GetSwitchUseCase>();
- services.AddScoped<GetSwitchesUseCase>();
- services.AddScoped<UpdateSwitchUseCase>();
- // NIC use cases
- services.AddScoped<AddNicUseCase>();
- services.AddScoped<UpdateNicUseCase>();
- services.AddScoped<RemoveNicUseCase>();
- // NIC commands
- services.AddScoped<ServerNicAddCommand>();
- services.AddScoped<ServerNicUpdateCommand>();
- services.AddScoped<ServerNicRemoveCommand>();
-
- // Drive commands
- services.AddScoped<ServerDriveAddCommand>();
- services.AddScoped<ServerDriveUpdateCommand>();
- services.AddScoped<ServerDriveRemoveCommand>();
-
- // GPU commands
- services.AddScoped<ServerGpuAddCommand>();
- services.AddScoped<ServerGpuUpdateCommand>();
- services.AddScoped<ServerGpuRemoveCommand>();
- // Spectre bootstrap
- app.Configure(config =>
- {
- config.SetApplicationName("rackpeek");
- // ----------------------------
- // Server commands (CRUD-style)
- // ----------------------------
- config.AddBranch("servers", server =>
- {
- server.SetDescription("Manage servers");
- server.AddCommand<ServerReportCommand>("summary")
- .WithDescription("Show server hardware report");
- server.AddCommand<ServerAddCommand>("add")
- .WithDescription("Add a new server");
- server.AddCommand<ServerGetByNameCommand>("get")
- .WithDescription("List servers or get a server by name");
- server.AddCommand<ServerDescribeCommand>("describe")
- .WithDescription("Show detailed information about a server");
- server.AddCommand<ServerSetCommand>("set")
- .WithDescription("Update server properties");
- server.AddCommand<ServerDeleteCommand>("del")
- .WithDescription("Delete a server");
- server.AddBranch("cpu", cpu =>
- {
- cpu.SetDescription("Manage server CPUs");
- cpu.AddCommand<ServerCpuAddCommand>("add")
- .WithDescription("Add a CPU to a server");
- cpu.AddCommand<ServerCpuSetCommand>("set")
- .WithDescription("Update a CPU on a server");
- cpu.AddCommand<ServerCpuRemoveCommand>("del")
- .WithDescription("Remove a CPU from a server");
- });
- server.AddBranch("nic", nic =>
- {
- nic.SetDescription("Manage server NICs");
- nic.AddCommand<ServerNicAddCommand>("add")
- .WithDescription("Add a NIC to a server");
- nic.AddCommand<ServerNicUpdateCommand>("set")
- .WithDescription("Update a NIC on a server");
- nic.AddCommand<ServerNicRemoveCommand>("del")
- .WithDescription("Remove a NIC from a server");
- server.AddBranch("drive", drive =>
- {
- drive.SetDescription("Manage server drives");
- drive.AddCommand<ServerDriveAddCommand>("add")
- .WithDescription("Add a drive to a server");
- drive.AddCommand<ServerDriveUpdateCommand>("set")
- .WithDescription("Update a drive on a server");
- drive.AddCommand<ServerDriveRemoveCommand>("del")
- .WithDescription("Remove a drive from a server");
- });
- server.AddBranch("gpu", gpu =>
- {
- gpu.SetDescription("Manage server GPUs");
- gpu.AddCommand<ServerGpuAddCommand>("add")
- .WithDescription("Add a GPU to a server");
- gpu.AddCommand<ServerGpuUpdateCommand>("set")
- .WithDescription("Update a GPU on a server");
- gpu.AddCommand<ServerGpuRemoveCommand>("del")
- .WithDescription("Remove a GPU from a server");
- });
- });
- config.AddBranch("switches", server =>
- {
- server.SetDescription("Manage switches");
- server.AddCommand<SwitchReportCommand>("summary")
- .WithDescription("Show switch hardware report");
- server.AddCommand<SwitchAddCommand>("add")
- .WithDescription("Add a new switch");
- server.AddCommand<SwitchGetByNameCommand>("get")
- .WithDescription("List switches or get a switches by name");
- server.AddCommand<SwitchDescribeCommand>("describe")
- .WithDescription("Show detailed information about a switch");
- server.AddCommand<SwitchSetCommand>("set")
- .WithDescription("Update switch properties");
- server.AddCommand<SwitchDeleteCommand>("del")
- .WithDescription("Delete a switch");
- });
- // ----------------------------
- // Reports (read-only summaries)
- // ----------------------------
- config.AddCommand<AccessPointReportCommand>("ap")
- .WithDescription("Show access point hardware report");
- config.AddCommand<DesktopReportCommand>("desktops")
- .WithDescription("Show desktop hardware report");
- config.AddCommand<UpsReportCommand>("ups")
- .WithDescription("Show UPS hardware report");
- config.ValidateExamples();
- });
- });
- }
- }
|