OtherSetCommand.cs 1019 B

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