gruntjs / gruntjs/gruntjs.com

Run parametrized task using grunt.task.run(taskname)

Open
#235 2 comments 0 reactions 0 assignees View on GitHub
content: API
Dominant language
Less
Stars
155
Forks
83
PR merge metrics
No merged PRs in 30d

Description

I looked at Grunt API docs but couldn't find a way to run a parametrized task using grunt.task.run(taskname). In this case, the taskname parameter may have n number of arguements.

I have a simple task which accepts a parameter and prints the message on console:

```
grunt.registerTask('hello', 'greeting task', function(name) {
if(!name || !name.length)
grunt.warn('you need to provide a name');

console.log('hello ' + name + '!');

});
```

I call the above task using below task which validates the task and if task exists then it runs it:

```
grunt.registerTask('validateandruntask', 'if task available then run given task', function(taskname) {
if(!taskname || !taskname.length) {
grunt.warn('task name is needed to run this task');
}

if(!grunt.task.exists(taskname)) {
grunt.log.writeln('this task does not exist!');
} else {
grunt.log.writeln(taskname + ' exists. Going to run this task');
grunt.task.run(taskname);
}

});
```

Now from command line, I am passing 'hello' task as parameter to 'validateandruntask' but I am not been able to pass the parameter to 'hello' task from command line:

This is what I tried on command line but it didn't work:

_grunt validateandruntask:hello=foo_

_grunt validateandruntask:hello:param=name_

Is this supported as part of grunt.task.run API or does application need to take care of this by passing additional parameter for child tasks to parent task (in this case, validateandruntask) which will run parametrized tasks?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.