mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-07-09 17:28:45 +00:00
feat: commands
This commit is contained in:
parent
946b9c7dee
commit
2a2dc0e99f
1 changed files with 47 additions and 1 deletions
|
|
@ -1,7 +1,9 @@
|
|||
#!/usr/bin/env node
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { cwd } from "node:process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { sendIpcRequest } from "./ipc/client.ts";
|
||||
import { serve } from "./serve.ts";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
|
|
@ -12,10 +14,22 @@ const packageJson = JSON.parse(readFileSync(join(__dirname, "../package.json"),
|
|||
|
||||
function printHelp(): void {
|
||||
console.log(
|
||||
`orchestrator v${packageJson.version}\n\nUsage:\n orchestrator serve\n orchestrator --help\n orchestrator --version`,
|
||||
`orchestrator v${packageJson.version}\n\nUsage:\n orchestrator serve\n orchestrator list\n orchestrator spawn [--cwd <path>] [--label <label>]\n orchestrator status <instance-id>\n orchestrator stop <instance-id>\n orchestrator --help\n orchestrator --version`,
|
||||
);
|
||||
}
|
||||
|
||||
function printResponse(response: unknown): void {
|
||||
console.log(JSON.stringify(response, null, 2));
|
||||
}
|
||||
|
||||
function getFlagValue(args: string[], flag: string): string | undefined {
|
||||
const index = args.indexOf(flag);
|
||||
if (index === -1 || index + 1 >= args.length) {
|
||||
return undefined;
|
||||
}
|
||||
return args[index + 1];
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
|
|
@ -34,6 +48,38 @@ async function main(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (args[0] === "list") {
|
||||
printResponse(await sendIpcRequest({ type: "list" }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0] === "spawn") {
|
||||
const spawnCwd = getFlagValue(args, "--cwd") ?? cwd();
|
||||
const label = getFlagValue(args, "--label");
|
||||
printResponse(await sendIpcRequest({ type: "spawn", cwd: spawnCwd, label }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0] === "status") {
|
||||
const instanceId = args[1];
|
||||
if (!instanceId) {
|
||||
console.error("Usage: orchestrator status <instance-id>");
|
||||
process.exit(1);
|
||||
}
|
||||
printResponse(await sendIpcRequest({ type: "status", instanceId }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0] === "stop") {
|
||||
const instanceId = args[1];
|
||||
if (!instanceId) {
|
||||
console.error("Usage: orchestrator stop <instance-id>");
|
||||
process.exit(1);
|
||||
}
|
||||
printResponse(await sendIpcRequest({ type: "stop", instanceId }));
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(`Unknown command: ${args[0]}`);
|
||||
printHelp();
|
||||
process.exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue