我正在使用 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/