Skip to content

Commit

Permalink
a $0 like in perl
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Oct 13, 2010
1 parent e9d39a5 commit e688370
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/optimist.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,16 @@ function Argv (args) {
};

function fail (msg) {
if (usage) console.error(
// not very robust:
usage.replace(/\$0/g,
process.env._.match(/(^|\/)(node|env)$/)
? process.argv.slice(0,2).join(' ')
: process.env._
)
);
if (usage) console.error(usage.replace(/\$0/g, self.$0))
console.error(msg);
process.exit();
}

self.$0 = process.env._.match(/(^|\/)(node|env)$/)
? process.argv.slice(0,2).join(' ')
: process.env._
;

self.check = function (f) {
try {
if (f(self.argv) === false) fail(err);
Expand Down

0 comments on commit e688370

Please sign in to comment.