9

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
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
thenm
  • 201
  • 4
  • 9

1 Answers1

13

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.

Adrian Theodorescu
  • 11,664
  • 2
  • 23
  • 30