Skip to content

Commit

Permalink
fixed setopt() and showHelp() to ignore "node" at argv[0] if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Mar 25, 2011
1 parent ca977b2 commit b13f632
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/getopt.js
Expand Up @@ -7,9 +7,11 @@ function stringRepeat(str, num) {
}

exports.showHelp = function (title, cb) {
var path = require('path');

console.log(" %s", title);
console.log(" ------------------");
console.log(" %s <options>", process.argv[0]);
console.log(" %s <options>", path.basename(process.argv[path.basename(process.execPath) == process.argv[0] ? 1 : 0]));
console.log("");

var list = [],
Expand Down Expand Up @@ -70,8 +72,11 @@ exports.getopt = function (cb) {
}
};
exports.setopt = function (o, args) {
if (typeof args == "undefined") args = process.argv.slice(2);
if (typeof args.length == "undefined") args = args.split(/\s+/);
if (typeof args == "undefined") {
var path = require('path');
// allows argv like "node script.js params" and "script.js params"
args = process.argv.slice(path.basename(process.execPath) == process.argv[0] ? 2 : 1);
}

opt_defs = o;

Expand Down

0 comments on commit b13f632

Please sign in to comment.