DesktopSetCommand.cs 913 B

1234567891011121314151617181920212223242526
  1. using Microsoft.Extensions.DependencyInjection;
  2. using RackPeek.Domain.Resources.Desktops;
  3. using Spectre.Console;
  4. using Spectre.Console.Cli;
  5. namespace Shared.Rcl.Commands.Desktops;
  6. public class DesktopSetSettings : DesktopNameSettings {
  7. [CommandOption("--model")] public string? Model { get; set; }
  8. }
  9. public class DesktopSetCommand(IServiceProvider provider)
  10. : AsyncCommand<DesktopSetSettings> {
  11. public override async Task<int> ExecuteAsync(
  12. CommandContext context,
  13. DesktopSetSettings settings,
  14. CancellationToken cancellationToken) {
  15. using IServiceScope scope = provider.CreateScope();
  16. UpdateDesktopUseCase useCase = scope.ServiceProvider.GetRequiredService<UpdateDesktopUseCase>();
  17. await useCase.ExecuteAsync(settings.Name, settings.Model);
  18. AnsiConsole.MarkupLine($"[green]Desktop '{settings.Name}' updated.[/]");
  19. return 0;
  20. }
  21. }