Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs 在GrunFile中指定多个选项_Gruntjs - Fatal编程技术网

Gruntjs 在GrunFile中指定多个选项

Gruntjs 在GrunFile中指定多个选项,gruntjs,Gruntjs,我已指定以下grunt任务: grunt.registerTask('build', function() { var apiUrl = grunt.option('api') || 'default'; var local = grunt.option('local'); grunt.log.writeln('Using api url: ' + apiUrl); grunt.log.writeln('Using local: ' + local); }); local应该是

我已指定以下grunt任务:

grunt.registerTask('build', function() {
  var apiUrl = grunt.option('api') || 'default';
  var local = grunt.option('local');
  grunt.log.writeln('Using api url: ' + apiUrl);
  grunt.log.writeln('Using local: ' + local);
});
local应该是一个布尔值

参数的值取决于命令行上的顺序。这种行为是不受欢迎的

如果我将本地参数放在最后,则一切都会按预期工作:

$ grunt build --api localhost --local
Running "build" task
Using api url: localhost
Using local: true
否则,值会出错:

$ grunt build --local --api localhost
Warning: Task "localhost" not found. Use --force to continue.

Aborted due to warnings.
$ grunt build --local --api=localhost
Running "build" task
Using api url: default
Using local: --api=localhost

Done, without errors.
我可以使用目标而不是布尔选项,但我想知道发生了什么。
我做错了什么?

我也有同样的错误,我知道我必须始终给参数赋值,使用=:

转换:

grunt build --api localhost --local

grunt build --api=localhost --local=true