[CLI] Convert a Single Command CLI into a Multi Command CLI with Oclif and TypeScript
typescript and with Command CLI INTO multi convert
2023-09-14 08:59:14 时间
Heavy duty CLI's like gatsby and npm do more than one thing. The convention is to namespace them with a command name after the CLI name, like gatsby new
or gatsby build
or npm install
or npm uninstall
. We should be comfortable converting our single purpose CLI's into multi command CLI's as our needs grow, as well as understand how to share logic between commands to keep code DRY.
Folder stucture:
We can put orignal index.ts into /commands/init.ts:
import {Command, flags} from '@oclif/command' class Mycli extends Command { static description = 'describe the command here' static flags = { // add --version flag to show CLI version version: flags.version({char: 'v'}), help: flags.help({char: 'h'}), // flag with a value (-n, --name=VALUE) name: flags.string({char: 'n', description: 'name to print'}), // flag with no value (-f, --force) force: flags.boolean({char: 'f'}), } static args = [{name: 'file'}] static strict = false async run() { const {argv, flags} = this.parse(Mycli) const name = flags.name || 'world' this.log(`hello egg ${name} from ./src/index.ts`) } } export = Mycli
/commands/build.ts
Have similar code as init.ts.
index.ts:
export {run} from '@oclif/command'
Run the init / build:
yarn mycli init
yarn mycli build
相关文章
- 快速掌握 TypeScript 新语法:infer extends
- typescript web_typescript在线运行
- typescript的泛型_泛型有什么用
- typescript 接口_typeScript
- TypeScript 实用工具类型之 Partial 类型
- TypeScript介绍和使用
- TypeScript,我从不喜欢到沉迷
- TypeScript 的装饰器有哪些?
- TypeScript方法装饰器应用
- 软件开发入门教程网之TypeScript 基础语法
- typescript [接口]
- 一道 3 层的 TypeScript 面试题,你能答到第几层?
- Typescript 全栈最值得学习的技术栈 TRPC
- TypeScript遭库开发者嫌弃:类型简直是万恶之源
- TypeScript实例_手动编译与自动编译、类型注解、接口和类的详解
- ORA-39322: Cannot use transportable tablespace with TIMESTAMP WITH TIME ZONE columns and different time zone version. ORACLE 报错 故障修复 远程处理
- 条件MySQL 子句之间`AND`操作符多条件查询(mysql多个and)
- Oracle数据库中的AND查询(oracle and查询)
- MySQL中AND的使用方法解析(mysql中and的用法)
- Mysql中强大的AND运算符的使用方法探究(mysql中and的使用)
- MySQL中的AND和OR使用逻辑运算符优化查询语句(mysql中and与or)
- Oracle 数据库中使用AND拼接的威力(oracle中and拼接)
- TypeScript 4.4 RC 发布