Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More than one --option #1005

Closed
shannonmoeller opened this issue Dec 5, 2013 · 4 comments
Closed

More than one --option #1005

shannonmoeller opened this issue Dec 5, 2013 · 4 comments
Milestone

Comments

@shannonmoeller
Copy link

The current documentation on using grunt.option is misleading. It says that boolean flags and options with values are supported, but what it doesn't tell you is that you can't have both at the same time.

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

I've written a plugin called nopt-grunt that provides a work around, but it's far from ideal. While it allows you to define and use options as expected, they get added too late in the process to be documented by grunt --help.

Misleading:

TODO:

@yuanyan
Copy link

yuanyan commented Dec 8, 2013

If you try grunt --bar=42 --foo, it's will be work right. Is this a bug of the nopt? @isaacs

@shannonmoeller
Copy link
Author

That is a workaround, not a fix. For example grunt test --bar=42 --foo --baz --bat will still behave inconsistently. The primary issue is that Gruntfile authors are not given a way to properly configure options. They can always parse the options themselves, but that's frustrating when Grunt already gets you 80% of the way there.

@yuanyan
Copy link

yuanyan commented Dec 9, 2013

I test the latest version of nopt that have fix this problem.

@vladikoff
Copy link
Member

This is a known issue, tracking in #908
Thanks!

@vladikoff vladikoff modified the milestones: 0.4.3, 0.4.4 Mar 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants