| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using Microsoft.Extensions.DependencyInjection;
- using RackPeek.Domain.Resources.SystemResources.UseCases;
- using Shared.Rcl.Commands.Servers;
- using Spectre.Console;
- using Spectre.Console.Cli;
- namespace Shared.Rcl.Commands.Systems;
- public class SystemSetSettings : ServerNameSettings
- {
- [CommandOption("--type")] public string? Type { get; set; }
- [CommandOption("--os")] public string? Os { get; set; }
- [CommandOption("--cores")] public int? Cores { get; set; }
- [CommandOption("--ram")] public int? Ram { get; set; }
- [CommandOption("--runs-on")] public string? RunsOn { get; set; }
- }
- public class SystemSetCommand(
- IServiceProvider serviceProvider
- ) : AsyncCommand<SystemSetSettings>
- {
- public override async Task<int> ExecuteAsync(
- CommandContext context,
- SystemSetSettings settings,
- CancellationToken cancellationToken)
- {
- using var scope = serviceProvider.CreateScope();
- var useCase = scope.ServiceProvider.GetRequiredService<UpdateSystemUseCase>();
- List<string> runsOn = new List<string>();
- if (settings.RunsOn is not null)
- {
- runsOn.Add(settings.RunsOn);
- }
- await useCase.ExecuteAsync(
- settings.Name,
- settings.Type,
- settings.Os,
- settings.Cores,
- settings.Ram,
- runsOn
- );
- AnsiConsole.MarkupLine($"[green]System '{settings.Name}' updated.[/]");
- return 0;
- }
- }
|