using System.CommandLine; using Hush.Config; using Hush.Daemon; using Spectre.Console; namespace Hush.Cli.Commands; public static class StopCommand { public static Command Create() { var command = new Command("stop", "Stop recording and process"); var profileOption = new Option(["--profile", "-p"], "Profile name to apply when processing"); command.AddOption(profileOption); command.SetHandler(async (context) => { var profileName = context.ParseResult.GetValueForOption(profileOption); try { await using var client = new SocketClient(); await client.ConnectAsync(TimeSpan.FromSeconds(2)); if (!string.IsNullOrEmpty(profileName)) { var config = new ConfigManager().LoadWithProfile(profileName); await client.SendCommandWithConfigAsync(DaemonProtocol.STOP, config); } else { await client.SendCommandAsync(DaemonProtocol.STOP); } AnsiConsole.MarkupLine("[green]Stop command sent[/]"); } catch (Exception ex) { AnsiConsole.MarkupLine($"[red]Error: {ex.Message}[/]"); context.ExitCode = 1; } }); return command; } }