谁能解释为什么下面的脚本没有显示所有命令的帮助?
test.js [command]
Commands:
test.js list-spaces List spaces
Options:
--help Show help [boolean]
--version Show version number [boolean]
请注意 list-commands
的帮助出于某种原因丢失。
#!/usr/bin/env node
'use strict'
const yargs = require("yargs");
yargs.command({
command: 'list-spaces',
describe: 'List spaces',
type: 'boolean',
handler: function(argv) {
console.log('aaa');
}
}).argv;
yargs.command({
command: 'list-connectors',
describe: 'List connectors',
builder: {
space: {
describe: 'space',
demandOption: true,
type: 'string'
},
},
handler: function(argv) {
console.log(argv.space);
}
}).argv;
答案 0 :(得分:2)
访问 .argv
是触发解析(process.args
)和输出生成的原因。来自the docs:
不带参数调用 .parse()
等同于调用 .argv
[…]
下面的其余方法在终止 .argv
或终止.parse()
之前出现。
您出于某种原因访问了 .argv
两次。第一次,第二个命令还没有注册。第二个语句甚至不再运行。