Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between command and option in [yargs]

Tags:

node.js

npm

yargs

I am using yargs for getting CLI arguments. I want to know the difference between command and option.

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

And

const argv = yargs
.option('address', {
  alias: 'a',
  demand: true,
  describe: 'Address for fetching weather'
})
.help()
.alias('help', 'h')
.argv
like image 597
thenm Avatar asked Jan 11 '18 06:01

thenm


1 Answers

One difference is semantics: commands perform actions, options alter the way the actions are to be performed. Another important difference is that options can be assigned values. For example:

git commit --message "Initial commit"

In the example above, commit is the command, and message is the option. The message option has a value of "Initial commit". You can also have options without values, which are referred to as "flags".

git fetch --no-tags

Here we're using the no-tags flag to tell Git to fetch everything from the upstream branch but exclude tags.

like image 159
Adrian Theodorescu Avatar answered Sep 28 '22 10:09

Adrian Theodorescu