Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

gruntjs - Grunt - Command Line Arguments, not working

I am using command line options in my grunt script: http://kurst.co.uk/transfer/Gruntfile.js

However the command grunt --vers:0.0.1 always returns 'undefined' when I try to get the option:

var version = grunt.option('vers') || ''; 

Can you help me get this working ?

I tried different (CLI) commands:

grunt vers:asd
grunt -vers:asd
grunt vers=asd

as well as using :

grunt.option('-vers');
grunt.option('--vers');

But no luck so far. Hopefully I am missing something simple.

This is my package.js file:

{
    "name": "",
    "version": "0.1.0",
    "description": "Kurst EventDispatcher / Docs Demo ",
    "devDependencies": {
        "grunt": "~0.4.1",
        "grunt-contrib-yuidoc": "*",
        "grunt-typescript": "~0.1.3",
        "uglify-js": "~2.3.5",
        "grunt-lib-contrib": "~0.6.0",
        "grunt-contrib-uglify":"*"
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The proper syntax for specifying a command line argument in Grunt is:

grunt --option1=myValue

Then, in the grunt file you can access the value and print it like this:

console.log( grunt.option( "option1" ) );

Also, another reason you are probably having issues with --vers is because its already a grunt option that returns the version:

★  grunt --vers
grunt-cli v0.1.7
grunt v0.4.1

So it would probably be a good idea to switch to a different option name.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...