Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

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

Notifications You must be signed in to change notification settings

shannonmoeller-archive/nopt-grunt

Repository files navigation

DEPRECATION NOTICE: This project is no longer maintained. Grunt has corrected the issues which made this plugin useful.

nopt-grunt

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

Build Status NPM version Dependency Status Stories in Ready Bitdeli Badge

Install

With Node.js

$ 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', []);
};

Known issues

grunt --help doesn't show my options

This plugin is a workaround for a to-do on the Grunt team's list. While it allows you to use the api as expected, options will not be displayed when using grunt --help. If you'd like to see this sort of functionality natively supported, go add your vote to my related Github issue.

License

MIT

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published