1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| const yargs = require('yargs/yargs')
const dedent = require('dedent') const pkg = require('../package.json')
const cli = yargs() const argv = process.argv.slice(2)
const context = { cliVersion: pkg.version }
cli .usage('Usage:lio-imooc-test [command] <options>') .demandCommand(1, 'A command is required. Pass --help to see all available commands and options.最少要输入一个参数') .strict() .recommendCommands() .fail((err, msg) => { console.log('err =======>', err) console.log('msg =======>', msg) }) .alias('h', 'help') .alias('v', 'version') .wrap(cli.terminalWidth()) .epilogue(dedent` hello world`) .options({ debug: { type: 'boolean', describe: 'Bootstrap debug mode', alias: 'd' } }) .option('ci', { type: 'string', describe: 'Define global registry', alias: 'r' }) .group(['debug'], 'Dev Options:') .group(['registry'], 'Extra Options:') .command('init [name]', 'Do init a project', (yargs) => { yargs .option('name', { type: 'string', describe: 'Name of a project', alias: 'n' }) }, (argv) => { console.log(argv) }) .command({ command: 'list', aliases: ['ls', 'la', 'll'], describe: 'List local packages', builder: (yargs) => {
}, handler: (argv) => { } }) .parse(argv, context)
|