/**
 * Custom help formatter for CLI
 * Provides enhanced help text with examples, categories, and better formatting
 */
import { colors, icons, section, subsection, command, example } from './colors.js';
/**
 * Command categories for organized help display
 */
export const commandCategories = [
    {
        name: 'Setup & Configuration',
        icon: icons.gear,
        commands: ['init', 'config'],
    },
    {
        name: 'Claude Desktop Integration',
        icon: icons.robot,
        commands: [
            'claude-desktop install',
            'claude-desktop update',
            'claude-desktop status',
            'claude-desktop uninstall',
        ],
    },
    {
        name: 'Data Management',
        icon: icons.database,
        commands: ['export-vcard', 'import-vcard', 'list-types'],
    },
];
/**
 * Command examples for enhanced help
 */
export const commandExamples = {
    init: [
        {
            description: 'Start interactive setup wizard',
            command: 'mcp-memory init',
        },
    ],
    config: [
        {
            description: 'Show current configuration',
            command: 'mcp-memory config',
        },
    ],
    'claude-desktop install': [
        {
            description: 'Install MCP server to Claude Desktop',
            command: 'mcp-memory claude-desktop install',
        },
    ],
    'claude-desktop update': [
        {
            description: 'Update MCP server configuration',
            command: 'mcp-memory claude-desktop update',
        },
    ],
    'claude-desktop status': [
        {
            description: 'Check installation status',
            command: 'mcp-memory claude-desktop status',
        },
    ],
    'claude-desktop uninstall': [
        {
            description: 'Remove MCP server from Claude Desktop',
            command: 'mcp-memory claude-desktop uninstall',
        },
    ],
    'export-vcard': [
        {
            description: 'Export all entities to vCard 4.0',
            command: 'mcp-memory export-vcard --user-email user@example.com',
        },
        {
            description: 'Export to specific file',
            command: 'mcp-memory export-vcard --user-email user@example.com -o contacts.vcf',
        },
        {
            description: 'Export all entity types',
            command: 'mcp-memory export-vcard --user-email user@example.com --all',
        },
    ],
    'import-vcard': [
        {
            description: 'Import vCard file',
            command: 'mcp-memory import-vcard contacts.vcf --user-email user@example.com',
        },
        {
            description: 'Preview import without saving',
            command: 'mcp-memory import-vcard contacts.vcf --user-email user@example.com --dry-run',
        },
        {
            description: 'Import with custom tags',
            command: 'mcp-memory import-vcard contacts.vcf --user-email user@example.com --tags "work,important"',
        },
    ],
    'list-types': [
        {
            description: 'Show available entity and person types',
            command: 'mcp-memory list-types',
        },
    ],
};
/**
 * Format custom help text for main program
 */
export function formatMainHelp(program) {
    const lines = [];
    // Header
    lines.push('');
    lines.push(colors.title(`${icons.rocket} MCP Memory TypeScript - Complete Management CLI`));
    lines.push('');
    lines.push(colors.description('Cloud-based vector memory service for AI assistants'));
    lines.push('');
    // Version
    lines.push(colors.dim(`Version: ${program.version()}`));
    lines.push('');
    // Usage
    lines.push(section('USAGE'));
    lines.push(`  ${command('mcp-memory')} ${colors.option('[command]')} ${colors.dim('[options]')}`);
    lines.push('');
    // Commands by category
    lines.push(section('COMMANDS'));
    for (const category of commandCategories) {
        lines.push('');
        lines.push(subsection(`${category.icon}  ${category.name}`));
        for (const cmdName of category.commands) {
            const cmd = findCommand(program, cmdName);
            if (cmd) {
                const padding = ' '.repeat(Math.max(0, 30 - cmdName.length));
                lines.push(`  ${command(cmdName)}${padding}${colors.description(cmd.description())}`);
            }
        }
    }
    // Global options
    lines.push('');
    lines.push(section('GLOBAL OPTIONS'));
    lines.push(`  ${colors.option('-h, --help')}                    Show help for command`);
    lines.push(`  ${colors.option('-V, --version')}                 Show version number`);
    // Quick start
    lines.push('');
    lines.push(section('QUICK START'));
    lines.push(`  ${colors.dim('1.')} Initialize configuration:    ${command('mcp-memory init')}`);
    lines.push(`  ${colors.dim('2.')} Install to Claude Desktop:  ${command('mcp-memory claude-desktop install')}`);
    lines.push(`  ${colors.dim('3.')} Check status:               ${command('mcp-memory claude-desktop status')}`);
    // Examples
    lines.push('');
    lines.push(section('EXAMPLES'));
    lines.push(`  ${colors.dim('#')} Get help for a specific command`);
    lines.push(`  ${example('$ mcp-memory claude-desktop install --help')}`);
    lines.push('');
    lines.push(`  ${colors.dim('#')} Export contacts to vCard`);
    lines.push(`  ${example('$ mcp-memory export-vcard --user-email user@example.com -o contacts.vcf')}`);
    // Footer
    lines.push('');
    lines.push(section('DOCUMENTATION'));
    lines.push(`  ${icons.book}  Full documentation: ${colors.link('https://github.com/your-repo/mcp-memory-ts')}`);
    lines.push('');
    lines.push(colors.dim('For more information on a specific command, run:'));
    lines.push(`  ${command('mcp-memory [command] --help')}`);
    lines.push('');
    return lines.join('\n');
}
/**
 * Format custom help text for a specific command
 */
export function formatCommandHelp(cmd, cmdName) {
    const lines = [];
    // Header
    lines.push('');
    lines.push(colors.title(`${icons.lightning} ${cmdName}`));
    lines.push('');
    lines.push(colors.description(cmd.description()));
    lines.push('');
    // Usage
    lines.push(section('USAGE'));
    const usage = cmd.usage();
    lines.push(`  ${command('mcp-memory ' + cmdName)} ${colors.dim(usage)}`);
    lines.push('');
    // Options
    const options = cmd.options;
    if (options.length > 0) {
        lines.push(section('OPTIONS'));
        for (const opt of options) {
            const flags = opt.flags;
            const desc = opt.description;
            const padding = ' '.repeat(Math.max(0, 35 - flags.length));
            lines.push(`  ${colors.option(flags)}${padding}${colors.description(desc)}`);
            if (opt.defaultValue !== undefined) {
                lines.push(`  ${' '.repeat(35)}${colors.dim(`(default: ${opt.defaultValue})`)}`);
            }
        }
        lines.push('');
    }
    // Examples
    const examples = commandExamples[cmdName];
    if (examples && examples.length > 0) {
        lines.push(section('EXAMPLES'));
        for (const ex of examples) {
            lines.push(`  ${colors.dim('#')} ${ex.description}`);
            lines.push(`  ${example('$ ' + ex.command)}`);
            lines.push('');
        }
    }
    // See also
    lines.push(section('SEE ALSO'));
    lines.push(`  ${colors.dim('Run')} ${command('mcp-memory --help')} ${colors.dim('for all available commands')}`);
    lines.push('');
    return lines.join('\n');
}
/**
 * Find a command by name (including subcommands)
 */
function findCommand(program, name) {
    const parts = name.split(' ');
    let current = program;
    for (const part of parts) {
        const found = current.commands.find(cmd => cmd.name() === part);
        if (!found)
            return undefined;
        current = found;
    }
    return current;
}
/**
 * Get all available command names (including subcommands)
 */
export function getAllCommandNames(program, prefix = '') {
    const names = [];
    for (const cmd of program.commands) {
        const fullName = prefix ? `${prefix} ${cmd.name()}` : cmd.name();
        names.push(fullName);
        // Add subcommands
        if (cmd.commands.length > 0) {
            names.push(...getAllCommandNames(cmd, fullName));
        }
    }
    return names;
}
/**
 * Format "did you mean" suggestion
 */
export function formatSuggestion(unknownCmd, suggestions) {
    const lines = [];
    lines.push('');
    lines.push(colors.error(`Unknown command '${unknownCmd}'`));
    lines.push('');
    if (suggestions.length > 0) {
        lines.push(colors.warning('Did you mean one of these?'));
        for (const suggestion of suggestions) {
            const cmd = findCommand(globalProgram, suggestion);
            const desc = cmd ? ` - ${colors.dim(cmd.description())}` : '';
            lines.push(`  ${colors.command('•')} ${command(suggestion)}${desc}`);
        }
        lines.push('');
    }
    lines.push(colors.dim(`Run ${command('mcp-memory --help')} for all commands`));
    lines.push('');
    return lines.join('\n');
}
// Global reference to program for suggestions
let globalProgram;
export function setGlobalProgram(program) {
    globalProgram = program;
}
//# sourceMappingURL=help.js.map