Files
RemSox/UI/CLI/Commands/ProcessCommands.cs
T
2026-06-08 22:05:11 +02:00

62 lines
1.5 KiB
C#

using RemSox.Processing;
namespace RemSox.UI.CLI.Commands;
public sealed class SpawnTestProcessCommand : ICommand
{
public string Name => "spawn test";
public string Description => "Spawn the test process";
public void Execute(string? arguments, Action<string> printLine)
{
int processId = ProcessManager.SpawnProcess<TestProcess>();
printLine($"Spawned TestProcess with ID {processId}");
}
}
public sealed class ListProcessesCommand : ICommand
{
public string Name => "ps";
public string Description => "List running processes";
public void Execute(string? arguments, Action<string> printLine)
{
IEnumerable<Process> processes = ProcessManager.GetAllProcesses();
printLine("Running processes:");
foreach (Process process in processes)
{
printLine($" ID: {process.Id}, Name: {process.Name}");
}
}
}
public sealed class StopProcessCommand : ICommand
{
public string Name => "stop";
public string Description => "Stop a process by ID";
public void Execute(string? arguments, Action<string> printLine)
{
string? idText = arguments;
if (string.IsNullOrWhiteSpace(idText))
{
printLine("Usage: stop <process-id>");
return;
}
if (int.TryParse(idText, out int processId))
{
ProcessManager.StopProcess(processId);
printLine($"Stopped process with ID {processId}");
return;
}
printLine("Invalid process ID");
}
}