# ibiz-cli **Repository Path**: iBizModeling/ibiz-cli ## Basic Information - **Project Name**: ibiz-cli - **Description**: No description available - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-04-16 - **Last Updated**: 2024-04-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # iBiz命令行工具 ## 目录说明 ```text |-- actions 与命令匹配的对应处理行为 |-- bin 入口目录 |-- commands 命令声明与命令注册 |-- core 核心包,基本工具类与接口 |-- tools 工具包 | `-- gulp 打包清理gulp插件 |-- LICENSE |-- README.md |-- gulpfile.js |-- package.json |-- tsconfig.json `-- yarn.lock ``` ## 本地开发 ```base // 在项目根目录 yarn // 启动项目 yarn dev // 本地全局安装,成功后可在命令行任意目录使用 npm link ``` ## 扩展 #### 1. 新增命令 1. 以新增link命令为例 2. 在commands目录下新建需要新增的命令link/link.ts文件。 3. link命令类继承CommandBase类 ```typescript export class LinkCommand extends CommandBase { } ``` 4. 实现抽象方法load,用于注册命令 ```typescript protected load(program: CommanderStatic): void { program .command('link') .arguments(' ') .description('建立软链接', { source: '需要链接的「文件、文件夹」', target: '链接至的目标目录', }) .usage(' ') .option('-f, --force', '当指向的目标文件存在时,删除原有[文件 or 文件夹]并建立软链接!') .action(async (source: string, target: string, options: Record, _command: Command) => { const input: Input = {}; input.source = { name: 'source', value: source }; input.target = { name: 'target', value: target }; const opts: Input = {}; opts.force = { name: 'force', value: options.force }; try { await this.action.handle(input, opts); } catch (err) { if (isError(err)) { log.error('', err.message); process.exit(10); } else { process.exit(0); } } }); } ``` 5. 在commands/loader/loader.ts的load方法中进行命令注册 ```typescript public static load(program: CommanderStatic): void { new LinkCommand(program); new LinkModelCommand(program); this.handleInvalidCommand(program); } ``` 6. 实现getAction抽象方法注册行为。 #### 2. 补充命令处理行为 1. 补充link的处理行为 2. 在actions目录下新建link/link.ts行为处理文件 3. link行为处理继承ActionBase ```typescript export class LinkAction extends ActionBase ``` 4. 实现handle抽象方法,用于处理命令。 ```typescript async handle(input: Input, options: Input, _extraFlags?: string[]): Promise { const { source, target } = input; const { force } = options; linkDir(source.value, target.value, force.value); } ```