4
0

SystemSetCommand.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.SystemResources.UseCases;
  4. using Shared.Rcl.Commands.Servers;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.Systems;
  8. public class SystemSetSettings : ServerNameSettings {
  9. [CommandOption("--type")] public string? Type { get; set; }
  10. [CommandOption("--os")] public string? Os { get; set; }
  11. [CommandOption("--cores")] public int? Cores { get; set; }
  12. [CommandOption("--ram")] public int? Ram { get; set; }
  13. [CommandOption("--runs-on <RUNSON>")]
  14. [Description("The physical machine(s) the service is running on.")]
  15. public string[]? RunsOn { get; set; }
  16. [CommandOption("--ip")]
  17. [Description("The ip address of the system.")]
  18. public string? Ip { get; set; }
  19. }
  20. public class SystemSetCommand(
  21. IServiceProvider serviceProvider
  22. ) : AsyncCommand<SystemSetSettings> {
  23. public override async Task<int> ExecuteAsync(
  24. CommandContext context,
  25. SystemSetSettings settings,
  26. CancellationToken cancellationToken) {
  27. using IServiceScope scope = serviceProvider.CreateScope();
  28. UpdateSystemUseCase useCase = scope.ServiceProvider.GetRequiredService<UpdateSystemUseCase>();
  29. await useCase.ExecuteAsync(
  30. settings.Name,
  31. settings.Type,
  32. settings.Os,
  33. settings.Cores,
  34. settings.Ram,
  35. settings.Ip,
  36. settings.RunsOn?.ToList()
  37. );
  38. AnsiConsole.MarkupLine($"[green]System '{settings.Name}' updated.[/]");
  39. return 0;
  40. }
  41. }