Permalink
Browse files

[api] Remove `.describe()` in favor of building upon the existing `.u…

…sage()` API
  • Loading branch information...
1 parent edbd527 commit d85f431ad7d07b058af3f2a57daa51495576c164 @indexzero indexzero committed May 14, 2011
Showing with 10 additions and 16 deletions.
  1. +1 −1 examples/{describe.js → usage-options.js}
  2. +9 −15 index.js
@@ -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,
View
@@ -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);
@@ -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 = [],
@@ -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) {

0 comments on commit d85f431

Please sign in to comment.