@five-vm/cli
Version:
High-performance CLI for Five VM development with WebAssembly integration
233 lines • 8.27 kB
JavaScript
/**
* Five CLI Help Command
*
* Provides comprehensive help with retro 2000s styling and proper
* command-specific help functionality.
*/
import chalk from 'chalk';
import { createSectionHeader, styleCommandExample, createInfoBox } from '../utils/ascii-art.js';
import { commands, getCommand } from './index.js';
/**
* Five help command implementation
*/
export const helpCommand = {
name: 'help',
description: 'Display help information for commands',
aliases: ['h', '-h', '--help'],
options: [
{
flags: '--detailed',
description: 'Show detailed help with examples',
defaultValue: false
},
{
flags: '--no-banner',
description: 'Skip the ASCII art banner',
defaultValue: false
}
],
arguments: [
{
name: 'command',
description: 'Command to get help for',
required: false
}
],
examples: [
{
command: 'five help',
description: 'Show general help'
},
{
command: 'five help compile',
description: 'Show help for compile command'
},
{
command: 'five help --detailed',
description: 'Show detailed help with examples'
}
],
handler: async (args, options, context) => {
const commandName = args[0];
if (commandName) {
// Show help for specific command
await showCommandHelp(commandName, options, context);
}
else {
// Show general help
await showGeneralHelp(options, context);
}
}
};
/**
* Show help for a specific command
*/
async function showCommandHelp(commandName, options, context) {
const command = getCommand(commandName);
if (!command) {
console.log(chalk.red(`Unknown command: ${commandName}`));
console.log('\nAvailable commands:');
showCommandList();
return;
}
// Command-specific help with styling
console.log(createSectionHeader(`Help: ${command.name}`, 'cyan'));
console.log();
// Description
console.log(chalk.bold('Description:'));
console.log(` ${command.description}`);
console.log();
// Aliases
if (command.aliases && command.aliases.length > 0) {
console.log(chalk.bold('Aliases:'));
console.log(` ${command.aliases.map(alias => chalk.cyan(alias)).join(', ')}`);
console.log();
}
// Usage
console.log(chalk.bold('Usage:'));
const usage = buildUsageString(command);
console.log(` ${chalk.cyan('five')} ${chalk.yellow(command.name)} ${usage}`);
console.log();
// Arguments
if (command.arguments && command.arguments.length > 0) {
console.log(chalk.bold('Arguments:'));
for (const arg of command.arguments) {
const argName = arg.required ? `<${arg.name}>` : `[${arg.name}]`;
const variadic = arg.variadic ? '...' : '';
console.log(` ${chalk.green(argName + variadic).padEnd(20)} ${arg.description}`);
}
console.log();
}
// Options
if (command.options && command.options.length > 0) {
console.log(chalk.bold('Options:'));
for (const option of command.options) {
const flags = chalk.green(option.flags);
const desc = option.description;
const defaultVal = option.defaultValue !== undefined ?
chalk.gray(` (default: ${option.defaultValue})`) : '';
console.log(` ${flags.padEnd(30)} ${desc}${defaultVal}`);
}
console.log();
}
// Examples
if (command.examples && command.examples.length > 0) {
console.log(chalk.bold('Examples:'));
for (const example of command.examples) {
console.log(styleCommandExample(example.command, example.description));
}
console.log();
}
}
/**
* Show general help with ASCII banner and command overview
*/
async function showGeneralHelp(options, context) {
// Show simple header unless disabled
if (!options.noBanner) {
console.log(chalk.bold.cyan('Five VM CLI - Ultra-fast bytecode VM for Solana'));
console.log(chalk.gray('The Future of Blockchain Execution'));
console.log();
}
// Show current configuration
showCurrentConfig(context);
// Command categories with styling
console.log(createSectionHeader('Available Commands', 'magenta'));
console.log();
const categories = {
'Development': ['compile', 'execute', 'local', 'test'],
'Deployment': ['deploy', 'deploy-and-execute'],
'Configuration': ['config'],
// 'Project Management': ['init'], // Disabled for now
'Utility': ['version', 'help']
};
for (const [category, commandNames] of Object.entries(categories)) {
console.log(chalk.bold.cyan(`${category}:`));
for (const cmdName of commandNames) {
const cmd = getCommand(cmdName);
if (cmd) {
const aliases = cmd.aliases ? chalk.gray(` (${cmd.aliases.join(', ')})`) : '';
console.log(` ${chalk.yellow(cmd.name)}${aliases.padEnd(20)} ${cmd.description}`);
}
}
console.log();
}
// Quick start examples
if (options.detailed) {
console.log(createSectionHeader('Quick Start Guide', 'green'));
console.log();
const quickStartExamples = [
'five init my-project Create a new Five project',
'five compile script.v Compile Five source to bytecode',
'five execute script.five --local Test execution locally',
'five deploy script.five --target devnet Deploy to Solana devnet',
'five config get View current configuration'
];
for (const example of quickStartExamples) {
const [cmd, desc] = example.split(' ');
console.log(styleCommandExample(cmd.trim(), desc?.trim() || ''));
}
console.log();
}
// Footer with useful info
console.log(createInfoBox('Need More Help?', [
'Use "five help <command>" for command-specific help',
'Use "five --verbose" for detailed output',
'Visit: https://github.com/five-vm/five-cli#readme'
]));
}
/**
* Show current configuration status
*/
function showCurrentConfig(context) {
// For now, show a simple status. In the future, integrate with ConfigManager
const configInfo = [
`${chalk.bold('Status:')} ${chalk.green('Ready')}`,
`${chalk.bold('Version:')} ${chalk.cyan('1.2.2')}`,
// `${chalk.bold('Network:')} ${getNetworkDisplay('local')}`, // TODO: Get from config
`${chalk.bold('Debug:')} ${context.options.debug ? chalk.yellow('ON') : chalk.gray('OFF')}`
];
console.log(createInfoBox('Current Status', configInfo));
console.log();
}
/**
* Build usage string from command definition
*/
function buildUsageString(command) {
const parts = [];
// Add options
if (command.options && command.options.length > 0) {
parts.push('[options]');
}
// Add arguments
if (command.arguments && command.arguments.length > 0) {
for (const arg of command.arguments) {
if (arg.required) {
parts.push(arg.variadic ? `<${arg.name}...>` : `<${arg.name}>`);
}
else {
parts.push(arg.variadic ? `[${arg.name}...]` : `[${arg.name}]`);
}
}
}
return parts.join(' ');
}
/**
* Show simplified command list
*/
function showCommandList() {
const commandNames = commands.map(cmd => cmd.name).sort();
const columns = 3;
const rows = Math.ceil(commandNames.length / columns);
for (let row = 0; row < rows; row++) {
const rowCommands = [];
for (let col = 0; col < columns; col++) {
const index = row + col * rows;
if (index < commandNames.length) {
rowCommands.push(chalk.cyan(commandNames[index].padEnd(15)));
}
}
console.log(` ${rowCommands.join('')}`);
}
}
//# sourceMappingURL=help.js.map