Skip to content
Lloyd Brookes edited this page Jan 16, 2018 · 5 revisions

A lazy multiple differs from a greedy multiple in that it requires you to specify the option name each time a value is passed.

Example

Lazy multiples are useful in cases where specifying an option multiple times increases it's "strength" in some way. Here, we have a --verbose option which can be amplified by setting it multiple times.

const commandLineArgs = require('command-line-args')
const optionDefinitions = [
  name: 'verbose',
  alias: 'v',
  type: Boolean,
  lazyMultiple: true
]
const options = commandLineArgs(optionDefinitions)
console.log(options)

In code, you could set different levels of verbosity by counting the number of times the option was set.

$ node example.js -vvv
{ verbose: [ true, true, true ] }