https://github.com/monajs/mona-commander
cli 底层服务
https://github.com/monajs/mona-commander
cli-command cli-engine
Last synced: 3 months ago
JSON representation
cli 底层服务
- Host: GitHub
- URL: https://github.com/monajs/mona-commander
- Owner: monajs
- License: mit
- Created: 2018-09-19T12:03:20.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-09T08:09:10.000Z (about 6 years ago)
- Last Synced: 2025-03-18T05:11:20.792Z (3 months ago)
- Topics: cli-command, cli-engine
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Commander
[](https://www.npmjs.com/package/@monajs/commander)
[](https://www.npmjs.com/package/@monajs/commander)
[](https://packagephobia.now.sh/result?p=@monajs/commander)✨✨ 一个简单的命令行底层工具!!!
```bash
$ npm i --save @monajs/commander
```### 使用指南
```js
#!/usr/bin/env nodeconst program = require('@monajs/commander')
program(options)
```
### 代码演示
- index.js
```js
#!/usr/bin/env nodeconst program = require('@monajs/commander')
const init = require('./init.js')const cmds = [{
command: 'init',
module: init,
aliases: 'in',
desc: '根据模版创建新项目'
}]program({
version: require('../package.json').version,
desc: '欢迎使用 mona-cli',
cmds
})```
- init.js
```js
exports.handler = argvs => {
console.log(argvs)
}```
#### options 属性介绍
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | :-- |
| version | 版本号 | `String` | `null` |
| desc | 命令描述(见下方注释) | `String` | `null` |
| cmds | 命令集合 | `Array` | `[]` |#### cmdItem 属性介绍
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | :-- |
| command | 命令执行模块名称 | `String` | `null` |
| module | 命令执行模块(见下方注释) | `String` | `404` |
| aliases | 命令执行模块别名 | `String` | `null` |
| desc | 命令执行模块介绍 | `String` | `null` |* 注:每一个命令执行模块都需要暴露出一个 `handler` 方法作为命令的入口
### 联系我
> 微信:yx12032331