为什么此 yargs 脚本帮助页面中缺少命令?

2024-03-25

有人可以解释为什么下面的脚本不显示所有命令的帮助吗?

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;

访问.argv是什么触发了解析(process.args)和输出生成。从the docs https://yargs.js.org/docs/#api-reference:

Calling .parse()不带参数相当于调用.argv

[…]

下面剩下的这些方法只是before the 终止 .argv或终止.parse().

您正在访问.argv由于某种原因两次。第一次时,第二个命令尚未注册。第二条语句甚至不再运行。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么此 yargs 脚本帮助页面中缺少命令? 的相关文章

随机推荐