33 lines
989 B
C#
33 lines
989 B
C#
using System;
|
|
using System.Net.Sockets;
|
|
using System.Threading.Tasks;
|
|
using Spectre.Console;
|
|
using Toak.Core;
|
|
|
|
namespace Toak.Commands;
|
|
|
|
public static class StartCommand
|
|
{
|
|
public static async Task ExecuteAsync(bool verbose)
|
|
{
|
|
Logger.Verbose = verbose;
|
|
var socketPath = DaemonService.GetSocketPath();
|
|
try
|
|
{
|
|
using var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
|
|
var endPoint = new UnixDomainSocketEndPoint(socketPath);
|
|
await socket.ConnectAsync(endPoint);
|
|
await socket.SendAsync(new byte[] { 1 }, SocketFlags.None);
|
|
if (verbose) Console.WriteLine("Sent START command to daemon.");
|
|
}
|
|
catch (SocketException)
|
|
{
|
|
AnsiConsole.MarkupLine("[red]Failed to connect to Toak daemon.[/]");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message}");
|
|
}
|
|
}
|
|
}
|