Files
baseos/ts/cli.ts
T

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-05-07 15:53:15 +00:00
import { BaseRunner } from './classes.baserunner.ts';
export async function runCli(argsArg: string[]) {
const command = argsArg[0] || 'start';
const runner = BaseRunner.fromEnv();
if (command === 'start') {
await runner.start();
await new Promise(() => undefined);
return;
}
if (command === 'status') {
await printJson(await runner.getRuntimeInfo());
return;
}
if (command === 'check-supervisor') {
await printJson({
configured: runner.supervisorClient.isConfigured(),
available: await runner.supervisorClient.isAvailable(),
address: runner.supervisorClient.address,
});
return;
}
if (command === 'request-update') {
await runner.requestSelfUpdate({ force: argsArg.includes('--force') });
await printJson({ ok: true });
return;
}
if (command === 'help' || command === '--help' || command === '-h') {
printHelp();
return;
}
console.error(`Unknown command: ${command}`);
printHelp();
Deno.exit(1);
}
async function printJson(dataArg: unknown) {
await Deno.stdout.write(new TextEncoder().encode(`${JSON.stringify(dataArg, null, 2)}\n`));
}
function printHelp() {
console.log(`BaseRunner commands:
start Start BaseRunner and keep the process alive
status Print runtime, supervisor, and Cloudly connection status
check-supervisor Check whether the Balena Supervisor API is available
request-update Ask the Balena Supervisor to check/apply app release updates
help Show this help text
`);
}