import { program, Command } from 'commander'; import { assistantConfig } from './config.ts'; import fs from 'fs'; // 将多个子命令加入主程序中 let version = '0.0.1'; try { // @ts-ignore if (ENVISION_VERSION) version = ENVISION_VERSION; } catch (e) {} // @ts-ignore program.name('asst').description('A CLI tool with envison').version(version, '-v, --version', 'output the current version'); const ls = new Command('ls').description('List files in the current directory').action(() => { console.log('List files'); console.log(fs.readdirSync(process.cwd())); }); program.addCommand(ls); export { program, Command, assistantConfig }; /** * 在命令行中运行程序 * 当前命令参数去执行 其他的应用模块 * @param args */ export const runProgram = (args: string[]) => { const [_app, _command] = process.argv; program.parse([_app, _command, ...args]); };