Files
flynn/src/cli/start.ts
T

40 lines
1.3 KiB
TypeScript

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());
});
});
}