node.js - [yargs] 中的命令和选项有什么区别

标签 node.js npm yargs

我正在使用 yargs 获取 CLI 参数。我想知道命令和选项之间的区别。

const argv = yargs
.command(
  'add',
  'Add a new note',
  {
    title: titleOptions,
    body: bodyOptions
  })
.argv;

const argv = yargs
.option('address', {
  alias: 'a',
  demand: true,
  describe: 'Address for fetching weather'
})
.help()
.alias('help', 'h')
.argv

最佳答案

一个区别是语义:命令执行操作,选项改变执行操作的方式。另一个重要的区别是选项可以赋值。例如:

git commit --message "Initial commit"

在上面的例子中,commit 是命令,message 是选项。 message 选项的值为“Initial commit”。您也可以有没有值的选项,这被称为“标志”。

git fetch --no-tags

这里我们使用 no-tags 标志告诉 Git 从上游分支获取所有内容但排除标签。

关于node.js - [yargs] 中的命令和选项有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48200876/

相关文章:

node.js - Socket.IO 按名称删除房间

node.js - 如何防止重复请求损害我的服务器

linux - 如何选择我的 npm 路径?

typescript - 如何制作依赖于先前值的 typescript 定义?

node.js - Yargs:在命令处理程序中调用现有命令

javascript - 无需过多嵌套即可调用多个 API

node.js - 带有 Webpack、Typescript 和 ES6 的 elastic-apm-node 不工作?

node.js - grunt-browser-sync 疯狂 : opening multiple instances of the browser over and over again

css - 如何仅为我的自定义 vue 组件包含外部 css 文件?

javascript - yargs 选项的可选参数