Skip to content

Commit

Permalink
[api] Remove .describe() in favor of building upon the existing `.u…
Browse files Browse the repository at this point in the history
…sage()` API
  • Loading branch information
indexzero committed May 14, 2011
1 parent edbd527 commit d85f431
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/describe.js → examples/usage-options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var optimist = require('./../index');

var argv = optimist.describe('This is my awesome program', {
var argv = optimist.usage('This is my awesome program', {
'about': {
description: 'Provide some details about the author of this program',
required: true,
Expand Down
24 changes: 9 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,17 @@ function Argv (args, cwd) {
rescan();

var usage;
self.usage = function (msg) {
self.usage = function (msg, opts) {
if (!opts && typeof msg === 'object') {
opts = msg;
msg = null;
}

usage = msg;
return self;
return opts ? self.options(opts) : self;
};

function fail (msg) {
if (usage) console.error(usage.replace(/\$0/g, self.$0))
console.error(msg);
self.showHelp();
process.exit(1);
Expand Down Expand Up @@ -245,16 +249,6 @@ function Argv (args, cwd) {
return a[l].length;
}

self.describe = function (desc, opts) {
if (!opts && typeof desc === 'object') {
opts = desc;
desc = null;
}

self.description = desc;
return opts ? self.options(opts) : self;
}

self.options = function (opts) {
var required = [],
strings = [],
Expand Down Expand Up @@ -317,8 +311,8 @@ function Argv (args, cwd) {
};

self.showHelp = function (padding) {
if (self.description) {
console.log(self.description + '\n');
if (usage) {
console.error(usage.replace(/\$0/g, self.$0));
}

if (self.options && Object.keys(self.options).length > 0) {
Expand Down

0 comments on commit d85f431

Please sign in to comment.