AccessPointSetCommand.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.AccessPoints;
  4. using Shared.Rcl.Commands.Servers;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.AccessPoints;
  8. public class AccessPointSetSettings : ServerNameSettings
  9. {
  10. [CommandOption("--model")]
  11. [Description("The access point model name.")]
  12. public string? Model { get; set; }
  13. [CommandOption("--speed")]
  14. [Description("The speed of the access point in Gb.")]
  15. public double? Speed { get; set; }
  16. }
  17. public class AccessPointSetCommand(
  18. IServiceProvider serviceProvider
  19. ) : AsyncCommand<AccessPointSetSettings>
  20. {
  21. public override async Task<int> ExecuteAsync(
  22. CommandContext context,
  23. AccessPointSetSettings settings,
  24. CancellationToken cancellationToken)
  25. {
  26. using var scope = serviceProvider.CreateScope();
  27. var useCase = scope.ServiceProvider.GetRequiredService<UpdateAccessPointUseCase>();
  28. await useCase.ExecuteAsync(
  29. settings.Name,
  30. settings.Model,
  31. settings.Speed
  32. );
  33. AnsiConsole.MarkupLine($"[green]Access Point '{settings.Name}' updated.[/]");
  34. return 0;
  35. }
  36. }