Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from davidaurelio/master
Browse files Browse the repository at this point in the history
Exit with status code 1 on incorrect usage
  • Loading branch information
harthur committed Jan 15, 2012
2 parents 7dcbed7 + 3b5dc30 commit 15078d9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions nomnom.js
Expand Up @@ -117,9 +117,9 @@ ArgParser.prototype = {
},

parse : function(argv) {
this.print = this.print || function(str) {
console.log(str);
process.exit(0);
this.print = this.print || function(str, code) {
console.log(str + '\n');
process.exit(code || 0);
};
this._help = this._help || "";
this._script = this._script || process.argv[0] + " "
Expand All @@ -142,7 +142,7 @@ ArgParser.prototype = {
this.command = command;
}
else if (arg) {
return this.print(this._script + ": no such command '" + arg + "'");
return this.print(this._script + ": no such command '" + arg + "'", 1);
}
else {
// no command but command expected e.g. 'git -v'
Expand Down Expand Up @@ -203,7 +203,7 @@ ArgParser.prototype = {
}
else {
that.print("'-" + (that.opt(last).name || last) + "'"
+ " expects a value\n\n" + that.getUsage());
+ " expects a value\n\n" + that.getUsage(), 1);
}
}
else {
Expand All @@ -225,7 +225,7 @@ ArgParser.prototype = {
}
else {
that.print("'--" + (that.opt(arg.full).name || arg.full) + "'"
+ " expects a value\n\n" + that.getUsage());
+ " expects a value\n\n" + that.getUsage(), 1);
}
}
else {
Expand Down Expand Up @@ -253,7 +253,7 @@ ArgParser.prototype = {
// exit if required arg isn't present
this.specs.forEach(function(opt) {
if (opt.required && options[opt.name] === undefined) {
this.print(opt.name + " argument is required\n\n" + this.getUsage());
this.print(opt.name + " argument is required\n\n" + this.getUsage(), 1);
}
}, this);

Expand Down Expand Up @@ -402,7 +402,7 @@ ArgParser.prototype.setOption = function(options, arg, value) {
var message = option.callback(value);

if (typeof message == "string") {
this.print(message);
this.print(message, 1);
}
}

Expand All @@ -416,7 +416,7 @@ ArgParser.prototype.setOption = function(options, arg, value) {

var name = option.name || arg;
if (option.choices && option.choices.indexOf(value) == -1) {
this.print(name + " must be one of: " + option.choices.join(", "));
this.print(name + " must be one of: " + option.choices.join(", "), 1);
}

if (option.list) {
Expand Down

0 comments on commit 15078d9

Please sign in to comment.