Skip to content

Commit

Permalink
don't show 'Options:' when there aren't any
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 16, 2011
1 parent e8d523d commit d614f63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ function Argv (args, cwd) {
};

self.help = function () {
var help = ['Options:'];

if (usage) {
help.unshift(usage.replace(/\$0/g, self.$0), '');
}

var keys = Object.keys(
Object.keys(descriptions)
.concat(Object.keys(demanded))
Expand All @@ -207,6 +201,12 @@ function Argv (args, cwd) {
}, {})
);

var help = keys.length ? [ 'Options:' ] : [];

if (usage) {
help.unshift(usage.replace(/\$0/g, self.$0), '');
}

var switches = keys.reduce(function (acc, key) {
acc[key] = [ key ].concat(aliases[key] || [])
.map(function (sw) {
Expand Down Expand Up @@ -241,7 +241,8 @@ function Argv (args, cwd) {
if (flags.strings[key]) type = '[string]';
if (dpadding.length > 0) desc += dpadding;

help.push(' ' + kswitch + spadding + [
var prelude = ' ' + kswitch + spadding;
var body = [
desc,
type,
demanded[key]
Expand All @@ -252,7 +253,9 @@ function Argv (args, cwd) {
? '[default: ' + JSON.stringify(defaults[key]) + ']'
: null
,
].filter(Boolean).join(' '));
].filter(Boolean).join(' ');

help.push(prelude + body);
});

help.push('');
Expand Down
1 change: 1 addition & 0 deletions test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports.usageFail = function () {
r.errors.join('\n').split(/\n+/),
[
'Usage: ./usage -x NUM -y NUM',
'Options:',
' -x [required]',
' -y [required]',
'Missing required arguments: y',
Expand Down

0 comments on commit d614f63

Please sign in to comment.