const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const dedent = require('dedent')
const arg = hideBin(process.argv) const cli = yargs(arg)
cli .usage('Usage: cli-test [command] <options>') .demandCommand(1, '最少输入一个命令') .strict() .recommendCommands() .alias('h', 'help') .alias('v', 'version') .epilogue(dedent(`底部的一行描述信息`)) .options({ debug: { type: 'boolean', describe: '启动 debug', alias: 'd', }, }) .option('regsitry', { type: 'string', describe: '全局的地址', alias: 'r', }) .group(['debug'], '开发选项') .command( 'init [name]', '项目初始化', (yargs) => { yargs.option('name', { type: 'string', describe: '项目名称', alias: 'n', }) }, (argv) => { console.log('argv ==>', argv) } ) .command({ command: 'list', aliases: ['ls', 'la', 'll'], describe: 'list 命令的描述信息', builder: (yargs) => {}, handler: (argv) => { console.log('fn argv =>', argv) }, }).argv
|