UNPKG

hayai-db

Version:

⚔ Instantly create and manage local databases with one command

49 lines (48 loc) • 2.43 kB
import { Command } from 'commander'; import chalk from 'chalk'; import { getDockerManager } from '../../core/docker.js'; export const logsCommand = new Command('logs') .description('View logs from a database instance') .argument('<name>', 'Database instance name') .option('-f, --follow', 'Follow log output') .option('-t, --tail <lines>', 'Number of lines to show from the end of the logs', parseInt) .option('--since <timestamp>', 'Show logs since timestamp (e.g. 2013-01-02T13:23:37Z)') .action(async (name, options) => { try { const dockerManager = getDockerManager(); await dockerManager.initialize(); const instance = dockerManager.getInstance(name); if (!instance) { console.error(chalk.red(`āŒ Database instance '${name}' not found`)); process.exit(1); } console.log(chalk.cyan(`šŸ“‹ Logs for '${name}':`)); console.log(chalk.gray('─'.repeat(50))); // NOTE: Docker logs integration implementation pending // Will use dockerode to stream real-time container logs console.log(chalk.yellow('🚧 Docker logs integration coming soon!')); console.log(chalk.gray('This will show real-time logs from the database container.')); if (options.follow) { console.log(chalk.gray('Following logs... (Press Ctrl+C to stop)')); // Simulate log following const logEntries = [ '2024-01-07 12:00:00 [INFO] Database server starting...', '2024-01-07 12:00:01 [INFO] Listening on port 5432', '2024-01-07 12:00:02 [INFO] Database ready to accept connections', '2024-01-07 12:00:03 [INFO] Connection established from 127.0.0.1', ]; for (const entry of logEntries) { console.log(chalk.gray(entry)); await new Promise(resolve => setTimeout(resolve, 1000)); } } console.log(chalk.yellow('\nšŸ’” Commands:')); console.log(' • hayai logs <name> -f - Follow logs in real-time'); console.log(' • hayai logs <name> -t 50 - Show last 50 lines'); console.log(' • hayai stop <name> - Stop the database'); } catch (error) { console.error(chalk.red('\nāŒ Failed to show logs:'), error instanceof Error ? error.message : error); process.exit(1); } });