DesktopSetCommand.cs 889 B

1234567891011121314151617181920212223242526272829
  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. {
  8. [CommandOption("--model")] public string? Model { get; set; }
  9. }
  10. public class DesktopSetCommand(IServiceProvider provider)
  11. : AsyncCommand<DesktopSetSettings>
  12. {
  13. public override async Task<int> ExecuteAsync(
  14. CommandContext context,
  15. DesktopSetSettings settings,
  16. CancellationToken cancellationToken)
  17. {
  18. using var scope = provider.CreateScope();
  19. var useCase = scope.ServiceProvider.GetRequiredService<UpdateDesktopUseCase>();
  20. await useCase.ExecuteAsync(settings.Name, settings.Model);
  21. AnsiConsole.MarkupLine($"[green]Desktop '{settings.Name}' updated.[/]");
  22. return 0;
  23. }
  24. }