47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
import process from "node:process";
|
|
import { runInstanceCommand } from "./cli/instance.js";
|
|
|
|
const COMMANDS = ["init", "setup", "start", "stop", "restart", "status", "logs", "doctor", "list"] as const;
|
|
type Command = typeof COMMANDS[number];
|
|
|
|
async function main(argv: string[]): Promise<number> {
|
|
if (argv.length === 0 || (argv.length === 1 && ["--help", "-h"].includes(argv[0]))) {
|
|
printHelp();
|
|
return 0;
|
|
}
|
|
|
|
const [command, ...args] = argv;
|
|
const option = argv.find((arg) => arg.startsWith("-"));
|
|
if (option) throw new Error(`Unknown option: ${option}`);
|
|
if (!COMMANDS.includes(command as Command)) throw new Error(`Unknown command: ${command}`);
|
|
if (command === "list") {
|
|
if (args.length !== 0) throw new Error("list does not accept <bot-id>");
|
|
} else if (args.length !== 1) {
|
|
throw new Error(`${command} requires exactly one <bot-id>`);
|
|
}
|
|
return runInstanceCommand(command, args);
|
|
}
|
|
|
|
function printHelp(): void {
|
|
console.log(`gori-agent - single-Bot ACP gateway
|
|
|
|
Usage:
|
|
gori-agent init <bot-id>
|
|
gori-agent setup <bot-id>
|
|
gori-agent start <bot-id>
|
|
gori-agent stop <bot-id>
|
|
gori-agent restart <bot-id>
|
|
gori-agent status <bot-id>
|
|
gori-agent logs <bot-id>
|
|
gori-agent doctor <bot-id>
|
|
gori-agent list
|
|
|
|
Instances root: \${GORI_AGENT_ROOT:-$HOME/.gori-agent}/instances`);
|
|
}
|
|
|
|
main(process.argv.slice(2)).then((code) => { if (Number.isInteger(code)) process.exitCode = code; }).catch((error) => {
|
|
console.error(error instanceof Error ? error.message : String(error));
|
|
process.exitCode = 1;
|
|
});
|