这是一个使用命令在 nodejs 中添加命令的简单示例:
'use strict';
const {Command} = require('commander');
const run = () => {
const program = new Command();
console.log('CMD');
program.command('cmd [opts...]')
.action((opts) => {
console.log('OPTS');
});
program.parse(process.argv);
};
run();
在这种情况下,一切正常,但是当我添加描述和选项时,commander
会引发错误:
program.command('cmd [opts...]', 'DESCRIPTION', {isDefault: true})
node test-commander.js cmd opts
test-commander-cmd(1) does not exist, try --help
我的环境:
node v8.9.3
npm 5.3.0
commander 2.12.2