4
0

AccessPointSetCommand.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. [CommandOption("--model")]
  10. [Description("The access point model name.")]
  11. public string? Model { get; set; }
  12. [CommandOption("--speed")]
  13. [Description("The speed of the access point in Gb.")]
  14. public double? Speed { get; set; }
  15. }
  16. public class AccessPointSetCommand(
  17. IServiceProvider serviceProvider
  18. ) : AsyncCommand<AccessPointSetSettings> {
  19. public override async Task<int> ExecuteAsync(
  20. CommandContext context,
  21. AccessPointSetSettings settings,
  22. CancellationToken cancellationToken) {
  23. using IServiceScope scope = serviceProvider.CreateScope();
  24. UpdateAccessPointUseCase useCase = scope.ServiceProvider.GetRequiredService<UpdateAccessPointUseCase>();
  25. await useCase.ExecuteAsync(
  26. settings.Name,
  27. settings.Model,
  28. settings.Speed
  29. );
  30. AnsiConsole.MarkupLine($"[green]Access Point '{settings.Name}' updated.[/]");
  31. return 0;
  32. }
  33. }