1
  var gulp = require("grunt");

    gulp.task('taskName', function(strng) {
        console.log(strng);
    });

Generally, the gulp file is run as "gulp taskName" I want to know how to pass "strng" with the taskName in command line as a parameter

Surya
  • 628
  • 3
  • 9
  • 26
  • http://stackoverflow.com/questions/23023650/is-it-possible-to-pass-a-flag-to-gulp-to-have-it-run-tasks-in-different-ways – Vova Bilyachat Mar 21 '16 at 10:09
  • cant we use something like gulp taskName:strng as in grunt – Surya Mar 21 '16 at 10:23
  • as i recall "gulp taskName:strng" its not an argument its calling subtask "strng" – Vova Bilyachat Mar 21 '16 at 10:28
  • without using yargs, cant we do it? How we will pass asrgument to the function taskName? – Surya Mar 21 '16 at 10:29
  • How about something like " gulp gulptask --strng value" ? – Paysdoc Mar 21 '16 at 21:09
  • yea, even I was thinking of the same. Let me be brief about my use case. I have a string which i need to manipulate as a valid string using a function with Gulp. I have a function, say, "function(string) { }". Using gulp gulptask --strng value...... How will I find out which is my string and value. Is is something like "--options 3". If so how may I proceed with such a use case. – Surya Mar 23 '16 at 04:29
  • Possible duplicate of [Pass Parameter to Gulp Task](http://stackoverflow.com/questions/28538918/pass-parameter-to-gulp-task) – revelt Jan 23 '17 at 10:40

1 Answers1

3

You may consider using yargs

reference: https://www.npmjs.com/package/yargs

In your gulpfile var args = require('yargs').argv;

In your command line $ gulp taskName --yourparamvariable=bar

To access the paramerter you've sent from your command line args.yourparamvariable

Khaled Awad
  • 1,644
  • 11
  • 24