SwitchSetCommand.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Switches;
  3. using Shared.Rcl.Commands.Servers;
  4. using Spectre.Console;
  5. using Spectre.Console.Cli;
  6. namespace Shared.Rcl.Commands.Switches;
  7. public class SwitchSetSettings : ServerNameSettings
  8. {
  9. [CommandOption("--Model")] public string Model { get; set; } = default!;
  10. [CommandOption("--managed")] public bool Managed { get; set; }
  11. [CommandOption("--poe")] public bool Poe { get; set; }
  12. }
  13. public class SwitchSetCommand(
  14. IServiceProvider serviceProvider
  15. ) : AsyncCommand<SwitchSetSettings>
  16. {
  17. public override async Task<int> ExecuteAsync(
  18. CommandContext context,
  19. SwitchSetSettings settings,
  20. CancellationToken cancellationToken)
  21. {
  22. using var scope = serviceProvider.CreateScope();
  23. var useCase = scope.ServiceProvider.GetRequiredService<UpdateSwitchUseCase>();
  24. await useCase.ExecuteAsync(
  25. settings.Name,
  26. settings.Model,
  27. settings.Managed,
  28. settings.Poe);
  29. AnsiConsole.MarkupLine($"[green]Switch '{settings.Name}' updated.[/]");
  30. return 0;
  31. }
  32. }