Process exits before displaying a large number of options (-h)
With a small number of options the output seems to work fine.
But with a long list, the process exits before finishing the console log. And it seems to get worse if you have longer help attributes.
Example options:
var opts = require('nomnom')
.options({
aa: {
required: false,
help: 'OPTIONAL: aa is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true
},
bb: {
abbr: 'b',
required: false,
help: 'OPTIONAL: bb is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
metavar: 'NUMBER',
'default': 10
},
cc: {
required: false,
help: 'OPTIONAL: cc is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
dd: {
abbr: 'd',
required: false,
help: 'OPTIONAL: dd is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
metavar: 'DD_STR'
},
ee: {
required: false,
help: 'OPTIONAL: ee is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
ff: {
required: false,
help: 'OPTIONAL: ff is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
gg: {
required: false,
help: 'OPTIONAL: gg is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
hh: {
required: false,
help: 'OPTIONAL: hh is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
ii: {
required: false,
help: 'OPTIONAL: ii is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
jj: {
required: false,
help: 'OPTIONAL: jj is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
kk: {
required: false,
help: 'OPTIONAL: kk is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
ll: {
required: false,
help: 'OPTIONAL: ll is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
mm: {
required: false,
help: 'OPTIONAL: mm is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
nn: {
required: false,
help: 'OPTIONAL: nn is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
oo: {
required: false,
help: 'OPTIONAL: oo is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
pp: {
required: false,
help: 'OPTIONAL: pp is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
qq: {
required: false,
help: 'OPTIONAL: qq is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
},
rr: {
required: false,
help: 'OPTIONAL: rr is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0',
flag: true,
'default': false
}
}).parse();
And the help output:
usage: node test [options]
options:
--aa OPTIONAL: aa is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
-b NUMBER, --bb NUMBER OPTIONAL: bb is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
--cc OPTIONAL: cc is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
-d DD_STR, --dd DD_STR OPTIONAL: dd is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
--ee OPTIONAL: ee is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
--ff OPTIONAL: ff is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
--gg OPTIONAL: gg is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
--hh OPTIONAL: hh is an example - with a decently long help string - 1 2 3 4 5 6 7 8 9 0
--ii OPTIONAL: ii is an example - with a decently long
Thanks for filing, this is definitely a bug. One solution is to print the usage in pieces instead of building it up into one string and printing it.
I'm starting to think it's not the process.exit that's the problem. If I take that out, in print, it will kick into my app after the partial output. But does not output the full thing.
I changed my print to this, and it worked:
this.print = this.print || function(str, code) {
var
parts = str.split('\n'),
i = 0, l = parts.length;
for(; i < l; i++) {
console.log(parts[i]);
}
process.exit(code || 0);
};
pull request?!
Just did.
Thanks putting together the pull request. I ran into this bug a few months ago, but I can't reproduce it anymore. Just curious, what's your node --version say?
v0.4.8
I upgraded to v0.6.x. That might have fixed the problem for me. You can check if doing the same works for you.
We still might want to take your fix though for anyone running on an older version.
Aye, it's likely due to the older version. I'm not sure when I'll be updating my version (on a work machine) but when I do I'll let you know.