Skip to content

Commit

Permalink
show help regardless of whether .argv has been called see #143
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Apr 10, 2015
1 parent c62efd6 commit 0d2dfc8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ function Argv (processArgs, cwd) {
}

self.showHelp = function (fn) {
if (!self.parsed) parseArgs(processArgs); // run parser, if it has not already been executed.
usage.showHelp(fn);
return self;
};
Expand Down
24 changes: 23 additions & 1 deletion test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,5 +1092,27 @@ describe('usage tests', function () {
''
]);
});
})
});

describe('showHelp', function(done) {
// see #143.
it('should show help regardless of whether argv has been called', function() {
var r = checkUsage(function () {
var y = yargs(['--foo'])
.options('foo', {
alias: 'f',
describe: 'foo option'
})
.wrap(null);

y.showHelp();
});

r.errors.join('\n').split(/\n+/).should.deep.equal([
'Options:',
' --foo, -f foo option',
''
]);
});
});
});

0 comments on commit 0d2dfc8

Please sign in to comment.