gruntjs / grunt

Grunt: The JavaScript Task Runner
http://gruntjs.com/
Other
12.26k stars 1.5k forks source link

Set multiple boolean CLI options? #1780

Open cradbold opened 7 years ago

cradbold commented 7 years ago

... but it doesn't appear that you do:

$> grunt deploy --test --staging
// grunt.option.flags(): --test=--staging,--pluginConfig=[object Object]
Krinkle commented 2 months ago

Indeed, https://gruntjs.com/api/grunt.option says:

Note that boolean options can be specified using just a key without a value. For example, running grunt deploy --staging on the command line would cause grunt.option('staging') to return true.

I tried to reproduce the issue you face a number of different ways, but it seems to work fine:

// Gruntfile.js
module.exports = function(grunt) {
  console.log(grunt.option.flags());
}

grunt v1.0.2 (released 2018):

$ npx grunt --version
grunt-cli v1.2.0
grunt v1.0.4

$ npx grunt --foo --bar
[ '--foo', '--bar' ]

$ npx grunt quux --foo --bar
[ '--foo', '--bar' ]

And on a more recent version:

$ npx grunt --version
grunt-cli v1.4.3
grunt v1.6.1

$ npx grunt --foo --bar
[ '--foo', '--bar', '--gruntfile=/gruntjs.com/Gruntfile.js' ]

$ npx grunt quux --foo --bar
[ '--foo', '--bar', '--gruntfile=/gruntjs.com/Gruntfile.js' ]