| 12345678910111213141516171819202122232425262728293031323334 |
- using System.ComponentModel;
- using Microsoft.Extensions.DependencyInjection;
- using RackPeek.Domain.Resources.Desktops;
- using RackPeek.Domain.UseCases.Ports;
- using Spectre.Console;
- using Spectre.Console.Cli;
- namespace Shared.Rcl.Commands.Desktops.Nics;
- public class DesktopNicRemoveSettings : CommandSettings {
- [CommandArgument(0, "<desktop>")]
- [Description("The desktop name.")]
- public string DesktopName { get; set; } = default!;
- [CommandArgument(1, "<index>")]
- [Description("The index of the nic to remove.")]
- public int Index { get; set; }
- }
- public class DesktopNicRemoveCommand(IServiceProvider provider)
- : AsyncCommand<DesktopNicRemoveSettings> {
- public override async Task<int> ExecuteAsync(
- CommandContext context,
- DesktopNicRemoveSettings settings,
- CancellationToken cancellationToken) {
- using IServiceScope scope = provider.CreateScope();
- IRemovePortUseCase<Desktop> useCase = scope.ServiceProvider.GetRequiredService<IRemovePortUseCase<Desktop>>();
- await useCase.ExecuteAsync(settings.DesktopName, settings.Index);
- AnsiConsole.MarkupLine($"[green]NIC #{settings.Index} removed from desktop '{settings.DesktopName}'.[/]");
- return 0;
- }
- }
|