This package has been deprecated

Author message:

No longer maintained. Grunt has corrected the issues which made this plugin useful.

nopt-grunt

0.1.1 • Public • Published

nopt-grunt Build Status

Allows additional command line options to be properly registered using nopt along with those natively supported by grunt.

Install

$ npm install nopt-grunt

Example

Grunt is awesome. Grunt's support for using additional command line options is not awesome. The current documentation is misleading in that they give examples of using boolean flags and options with values, but they don't tell you that it only works that way with a single option. Try and use more than one option and things fall apart quickly.

// Gruntfile.js -> grunt --foo
module.exports = function(grunt) {
    assert.strictEqual(grunt.option('foo'), true); // pass
    grunt.registerTask('default', []);
};
 
// Gruntfile.js -> grunt --bar=42
module.exports = function(grunt) {
    assert.strictEqual(grunt.option('bar'), 42);   // pass
    grunt.registerTask('default', []);
};
 
// Gruntfile.js -> grunt --foo --bar=42
module.exports = function(grunt) {
    assert.strictEqual(grunt.option('foo'), true); // fail -> foo === '--bar=42'
    assert.strictEqual(grunt.option('bar'), 42);   // fail -> bar === undefined
    grunt.registerTask('default', []);
};

Not helpful. Back to the documentation! Still not helpful. Enter nopt-grunt.

// Gruntfile.js -> grunt --foo --bar=42
module.exports = function(grunt) {
    // require it at the top and pass in the grunt instance
    require('nopt-grunt')(grunt);
 
    // new method now available
    grunt.initOptions({
        // longhand
        foo: {
            info: 'Some flag of interest.',
            type: Boolean
        },
 
        // shorthand
        bar: [Number, null]
    });
 
    assert.strictEqual(grunt.option('foo'), true); // pass!
    assert.strictEqual(grunt.option('bar'), 42);   // pass!
 
    // reference values as before
    grunt.option('no-foo');
 
    grunt.initConfig({});
    grunt.registerTask('default', []);
};

License

MIT

githalytics.com alpha

Dependencies (1)

Dev Dependencies (1)

Package Sidebar

Install

npm i nopt-grunt

Weekly Downloads

16

Version

0.1.1

License

MIT

Last publish

Collaborators

  • shannonmoeller