UNPKG

ursamu-mud

Version:

Ursamu - Modular MUD Engine with sandboxed scripting and plugin system

80 lines 2.93 kB
#!/usr/bin/env node /** * Ursamu CLI - Developer command-line interface */ import { Command } from 'commander'; import chalk from 'chalk'; import { ScriptCommands } from './commands/ScriptCommands.js'; import { DebugCommands } from './commands/DebugCommands.js'; import { ProfileCommands } from './commands/ProfileCommands.js'; import { ProjectCommands } from './commands/ProjectCommands.js'; import { CLIConfig } from './config/CLIConfig.js'; import { version } from '../version.js'; const program = new Command(); // Configure CLI program .name('ursamu-mud') .description('Ursamu CLI - Developer tools for modular MUD development') .version(version) .option('-v, --verbose', 'enable verbose logging') .option('-c, --config <path>', 'path to config file') .option('--no-color', 'disable colored output'); // Global error handling process.on('uncaughtException', (error) => { console.error(chalk.red('Uncaught Exception:'), error.message); if (program.opts().verbose) { console.error(error.stack); } process.exit(1); }); process.on('unhandledRejection', (reason, promise) => { console.error(chalk.red('Unhandled Rejection at:'), promise, chalk.red('reason:'), reason); process.exit(1); }); async function main() { try { // Initialize CLI configuration const config = new CLIConfig(); await config.load(program.opts().config); // Initialize command modules const scriptCommands = new ScriptCommands(config); const debugCommands = new DebugCommands(config); const profileCommands = new ProfileCommands(config); const projectCommands = new ProjectCommands(config); // Register commands scriptCommands.register(program); debugCommands.register(program); profileCommands.register(program); projectCommands.register(program); // Set up global options processing program.hook('preAction', (thisCommand) => { const opts = thisCommand.opts(); // Configure chalk based on color option if (opts.color === false) { chalk.level = 0; } // Set verbose mode globally if (opts.verbose) { config.setVerbose(true); } }); // Parse and execute command await program.parseAsync(process.argv); } catch (error) { console.error(chalk.red('CLI Error:'), error.message); if (program.opts().verbose && error instanceof Error) { console.error(chalk.gray(error.stack)); } process.exit(1); } } // Run CLI if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { main().catch((error) => { console.error(chalk.red('Fatal error:'), error.message); process.exit(1); }); } export { main }; //# sourceMappingURL=ursamu-cli.js.map