Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Node.js modules you should know about: optimist (catonmat.net)
47 points by pkrumins on Dec 2, 2011 | hide | past | favorite | 8 comments


The problem I have with optimist it that it provides no default usage statement (last time I checked). One of the big selling points of argument processors is that you can define the args and some descriptions so it will generate the usage statement. This cuts down of re-typing and errors. It also has the benefit of autocomplete tools being able to handle standard formats.


[1] demonstrates the use of default.

  var optimist= require('optimist')
    .alias({e:'email', hp:'homepage', a:'auto', '?':'help'})
    .default('auto',true)
I'm not sure whether I like the usage pattern of this code, which uses promises to resolve argv's[2]. I'll investigate having optimist autogenerate a usage statement; that would be convenient both as a dev and as a user.

  [1] https://github.com/rektide/git-ts/blob/master/publish.js#L3
  [2] https://github.com/rektide/git-ts/blob/master/publish.js#L102


Agreed - personally I use https://github.com/visionmedia/commander.js for this reason.


There are a few option parsers in node that do automatically generate usage. However, this is actually quite problematic if you have a lot of options.

Check out https://github.com/harthur/nomnom, it may be more to your liking.


I really like nomnom. It's a super tight way to define options and commands.


We've been using Optimist in house for a while, and are satisfied with it. Makes launching a bunch of different node processes with slightly different configurations pretty painless.


Can it handle multiple invocations of same argument? For example:

./foo.js -x 1 -x 2 -x 3

(should give an array [1, 2, 3] for 'x')


Substack does it again. Great node developer.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: