UNPKG

@five-vm/cli

Version:

High-performance CLI for Five VM development with WebAssembly integration

127 lines 3.98 kB
/** * Five CLI Commands Index * * Central registry for all Five CLI commands with automatic discovery * and registration capabilities. */ import chalk from 'chalk'; // Import all command definitions import { compileCommand } from './compile.js'; import { executeCommand } from './execute.js'; // import { analyzeCommand } from './analyze.js'; // Disabled until working import { deployCommand } from './deploy.js'; import { deployAndExecuteCommand } from './deploy-and-execute.js'; // onchainCommand removed - replaced by config-driven deploy/execute import { testCommand } from './test.js'; import { versionCommand } from './version.js'; import { configCommand } from './config.js'; import { localCommand } from './local.js'; import { helpCommand } from './help.js'; import { templateCommand } from './template.js'; import { donateCommand } from './donate.js'; /** * Registry of all available commands */ export const commands = [ helpCommand, // Put help first for priority templateCommand, donateCommand, compileCommand, executeCommand, deployCommand, deployAndExecuteCommand, localCommand, configCommand, // initCommand, // Disabled for now // analyzeCommand, // Disabled until working testCommand, versionCommand // onchainCommand removed - replaced by config-driven deploy/execute ]; /** * Get command by name or alias */ export function getCommand(name) { return commands.find(cmd => cmd.name === name || (cmd.aliases && cmd.aliases.includes(name))); } /** * Get all command names and aliases */ export function getAllCommandNames() { const names = []; for (const cmd of commands) { names.push(cmd.name); if (cmd.aliases) { names.push(...cmd.aliases); } } return names; } /** * Get commands by category */ export function getCommandsByCategory() { return { 'Development': [compileCommand, executeCommand, localCommand, testCommand, templateCommand], 'Deployment': [deployCommand, deployAndExecuteCommand], 'Support': [donateCommand], 'Configuration': [configCommand], // 'Project Management': [initCommand], // Disabled for now 'Utility': [versionCommand, helpCommand], // 'Legacy': [onchainCommand] - removed }; } /** * Generate help text for all commands with retro styling */ export function generateCommandsHelp() { const categories = getCommandsByCategory(); const helpSections = []; for (const [category, cmds] of Object.entries(categories)) { helpSections.push(`\n${chalk.bold.cyan(category + ':')}`); for (const cmd of cmds) { const aliases = cmd.aliases ? chalk.gray(` (${cmd.aliases.join(', ')})`) : ''; const cmdName = chalk.yellow(cmd.name); const desc = chalk.white(cmd.description); helpSections.push(` ${cmdName}${aliases.padEnd(20)} ${desc}`); } } return helpSections.join('\n'); } /** * Validate command definition */ export function validateCommand(cmd) { if (!cmd.name || typeof cmd.name !== 'string') { return false; } if (!cmd.description || typeof cmd.description !== 'string') { return false; } if (!cmd.handler || typeof cmd.handler !== 'function') { return false; } return true; } /** * Register a new command dynamically */ export function registerCommand(cmd) { if (!validateCommand(cmd)) { return false; } // Check for name conflicts if (getCommand(cmd.name)) { return false; } commands.push(cmd); return true; } // Export individual commands for direct access export { helpCommand, compileCommand, executeCommand, deployCommand, deployAndExecuteCommand, localCommand, configCommand, // initCommand, // Disabled for now // analyzeCommand, // Disabled until working testCommand, versionCommand // onchainCommand removed }; //# sourceMappingURL=index.js.map