mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using System;
|
|
using RemSox.Processing;
|
|
|
|
namespace RemSox.UI.GUI.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");
|
|
}
|
|
} |