gruntjs / grunt-cli

Grunt's command line interface.
http://gruntjs.com/
MIT License
706 stars 248 forks source link

Update nopt #102

Closed vladikoff closed 8 years ago

vladikoff commented 8 years ago

There is an issue in the update to latest nopt.

New version 3 of nopt:
{ gruntfile: true,
  argv: 
   { remain: [ 'some/Gruntfile.js' ],
     cooked: [ '--gruntfile', 'some/Gruntfile.js' ],
     original: [ '--gruntfile', 'some/Gruntfile.js' ] } }

Old version 1 of nopt:
{ gruntfile: 'some/Gruntfile.js',
  argv: 
   { remain: [],
     cooked: [ '--gruntfile', 'some/Gruntfile.js' ],
     original: [ '--gruntfile', 'some/Gruntfile.js' ],
     toString: [Function] } }

Ref: https://github.com/gruntjs/grunt-cli/issues/101

shama commented 8 years ago

This behavior is expected with grunt@1.0.0. See the release notes regarding nopt: http://gruntjs.com/blog/2016-02-11-grunt-1.0.0-rc1-released#api-changes

The new syntax should be grunt --gruntfile=some/path/Gruntfile.js.

vladikoff commented 8 years ago

@shama yeah this is tricky ...

Arkni commented 8 years ago

@vladikoff

In new versions of nopt, unknown options by default have true as value. See npm/nopt#16 for reference.

Also, from their README:

$ node my-program.js --blatzk -fp # unknown opts are ok.
{ blatzk: true, flag: true, pick: true }

$ node my-program.js --blatzk=1000 -fp # but you need to use = if they have a value
{ blatzk: 1000, flag: true, pick: true }

$ node my-program.js --no-blatzk -fp # unless they start with "no-"
{ blatzk: false, flag: true, pick: true }

To fix that and maintain compatibility with older cli version, you can add gruntfile and base to known options, without forgetting the base alias -b:

// CLI options we care about.
exports.known = {help: Boolean, version: Boolean, completion: String, gruntfile: String, base: String};
exports.aliases = {b: '--base', h: '--help', V: '--version', v: '--verbose'};
vladikoff commented 8 years ago

Yea @shama has more detail on this but basically we dropped backwards compat

Arkni commented 8 years ago

Ah, thanks :) Somehow I missed the new release.

shama commented 8 years ago

Oh sorry I wasn't aware of this behavior in nopt (thank you @Arkni!). If we can provide backwards compatibility for the known grunt options through the regular API of the latest version of nopt I think we should.

Here are the options Grunt knows about: https://github.com/gruntjs/grunt/blob/master/lib/grunt/cli.js#L33

@vladikoff I can look into this along with the bin issue this evening.