temp
This commit is contained in:
28
assistant/src/program.ts
Normal file
28
assistant/src/program.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { program, Command } from 'commander';
|
||||
import fs from 'fs';
|
||||
// 将多个子命令加入主程序中
|
||||
let version = '0.0.1';
|
||||
try {
|
||||
// @ts-ignore
|
||||
if (ENVISION_VERSION) version = ENVISION_VERSION;
|
||||
} catch (e) {}
|
||||
// @ts-ignore
|
||||
program.name('app').description('A CLI tool with envison').version(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 };
|
||||
|
||||
/**
|
||||
* 在命令行中运行程序
|
||||
* 当前命令参数去执行 其他的应用模块
|
||||
* @param args
|
||||
*/
|
||||
export const runProgram = (args: string[]) => {
|
||||
const [_app, _command] = process.argv;
|
||||
program.parse([_app, _command, ...args]);
|
||||
};
|
||||
Reference in New Issue
Block a user