DesktopDriveAddCommand.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.ComponentModel;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using RackPeek.Domain.Resources.Desktops;
  4. using RackPeek.Domain.UseCases.Drives;
  5. using Spectre.Console;
  6. using Spectre.Console.Cli;
  7. namespace Shared.Rcl.Commands.Desktops.Drive;
  8. public class DesktopDriveAddSettings : CommandSettings
  9. {
  10. [CommandArgument(0, "<desktop>")]
  11. [Description("The name of the desktop.")]
  12. public string DesktopName { get; set; } = default!;
  13. [CommandOption("--type")]
  14. [Description("The drive type e.g hdd / ssd.")]
  15. public string? Type { get; set; }
  16. [CommandOption("--size")]
  17. [Description("The drive capacity in GB.")]
  18. public int? Size { get; set; }
  19. }
  20. public class DesktopDriveAddCommand(IServiceProvider provider)
  21. : AsyncCommand<DesktopDriveAddSettings>
  22. {
  23. public override async Task<int> ExecuteAsync(
  24. CommandContext context,
  25. DesktopDriveAddSettings settings,
  26. CancellationToken cancellationToken)
  27. {
  28. using var scope = provider.CreateScope();
  29. var useCase = scope.ServiceProvider.GetRequiredService<IAddDriveUseCase<Desktop>>();
  30. await useCase.ExecuteAsync(settings.DesktopName, settings.Type, settings.Size);
  31. AnsiConsole.MarkupLine($"[green]Drive added to desktop '{settings.DesktopName}'.[/]");
  32. return 0;
  33. }
  34. }