import chalk from 'chalk'; import { getCommandAbsolutePaths } from '../utils/command'; import path from 'path'; import { marked } from 'marked'; import TerminalRenderer from 'marked-terminal'; marked.setOptions({ // Define custom renderer renderer: new TerminalRenderer() as any }); interface CommandArgs { commandName: string; } interface CommandOptions { help: string; description: string; required: Array<{ name: string; message: string; }>; args: Record; } const helpCommand = { async command(args: CommandArgs) { const commandPaths = getCommandAbsolutePaths(); for (const item of commandPaths) { const itemCommandName = path.basename(item).replace('_', ':').replace(/\.(js|ts)$/, ''); const itemModuleName = path.normalize(item).replace(/\.(js|ts)$/, ''); if (itemCommandName === args.commandName) { const rawOptions = await import(itemModuleName); const { commandOptions } = rawOptions.default ? rawOptions.default : rawOptions; console.log(marked(commandOptions.help)); return; } } console.log(chalk.red(`Command ${args.commandName} is not a known command.`)); }, commandOptions: { required: [ { name: "commandName", // <-- this value will be users message: 'You need a command name to get help for a command... duh', // <-- failure message if param does not exist }, ], help: ` Auditboard CLI Use this tool to create commands that will assist you while you build your application. To view a list of available commands, you may use the "list" command: auditboard list And other great commands that you'll create! `, description: "Displays help for a command", args: {} } as CommandOptions }; export default helpCommand;