#!/usr/bin/env node
const commander = require('commander')
const pkg = require('../package.json')
// 单例
// const {program} = commander
// 手动初始化一个实例
const program = new commander.Command()
program
.name(Object.keys(pkg.bin)[0])
.usage('<commander> [options]')
.version(pkg.version)
.option('-d, --debug', '是否启动debug模式', false)
.option('-e, --envName <envName>', '获取环境变量名称')
.parse(process.argv)
// 注册命令 command
// const clone = program.command('clone <source> [destination]')
// clone
// .description('克隆仓库')
// .option('-f --force', '是否强制克隆', false)
// .action((source, destination, cmdObj) => {
// console.log('this is command "clone"', source, destination, cmdObj.force)
// })
// program
// .command('clone')
// .argument('<source>', '仓库地址')
// .argument('[destination]', '仓库地址')
// .description('clone a repository')
// .action((source, destination, cmdObj) => {
// console.log('this is command "clone"', source, destination, cmdObj.title)
// })
// 注册命令 addCommand
const service = new commander.Command('service')
service
.command('start [port]')
.alias('s')
.description('start service by port')
.action((port) => {
console.log('do service start', port)
})
service
.command('stop')
.description("stop service")
.action(() => {
console.log('stop service')
})
program.addCommand(service)
program.parse(process.argv)
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星