feat(cli): add CLI entry point with commander and start command

This commit is contained in:
William Valentin
2026-02-05 22:14:42 -08:00
parent 6f7b5b8f0f
commit 72c75a8bd7
10 changed files with 175 additions and 8 deletions
+39
View File
@@ -0,0 +1,39 @@
import type { Command } from 'commander';
import { loadConfigSafe, getConfigPath } from './shared.js';
import { existsSync } from 'fs';
export function registerStartCommand(program: Command): void {
program
.command('start')
.description('Start the Flynn daemon')
.option('-c, --config <path>', 'Config file path')
.action(async (opts: { config?: string }) => {
const configPath = opts.config ?? getConfigPath();
if (!existsSync(configPath)) {
console.error(`Config file not found: ${configPath}`);
console.error('Run "flynn doctor" to diagnose, or create a config at ~/.config/flynn/config.yaml');
process.exit(1);
}
console.log('Flynn starting...');
console.log(`Loading config from: ${configPath}`);
const { config, error } = loadConfigSafe(configPath);
if (!config) {
console.error(error);
process.exit(1);
}
// Dynamic import to avoid loading daemon code for other commands
const { startDaemon } = await import('../daemon/index.js');
const daemon = await startDaemon(config);
console.log(`Allowed Telegram chat IDs: ${config.telegram.allowed_chat_ids.join(', ')}`);
// Keep process alive
await new Promise<void>((resolve) => {
daemon.lifecycle.onShutdown(async () => resolve());
});
});
}