thenm
thenm

Reputation: 211

What is the difference between command and option in [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

Upvotes: 9

Views: 3060

Answers (1)

Adrian Theodorescu
Adrian Theodorescu

Reputation: 12327

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.

Upvotes: 13

Related Questions