Skip to content

Commit

Permalink
fix --name clobbering. Closes #92
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Oct 10, 2012
1 parent 1fc8330 commit 2e4fe08
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function Command(name) {
this.commands = [];
this.options = [];
this.args = [];
this.name = name;
this._name = name;
}

/**
Expand Down Expand Up @@ -199,7 +199,7 @@ Command.prototype.parseExpectedArgs = function(args){

Command.prototype.action = function(fn){
var self = this;
this.parent.on(this.name, function(args, unknown){
this.parent.on(this._name, function(args, unknown){
// Parse any so-far unknown options
unknown = unknown || [];
var parsed = self.parseOptions(unknown);
Expand Down Expand Up @@ -344,7 +344,8 @@ Command.prototype.parse = function(argv){
this.rawArgs = argv;

// guess name
if (!this.name) this.name = basename(argv[1]);
this._name = this._name || basename(argv[1]);

// process argv
var parsed = this.parseOptions(this.normalize(argv.slice(2)));
this.args = parsed.args;
Expand Down Expand Up @@ -700,7 +701,7 @@ Command.prototype.commandHelp = function(){
Command.prototype.helpInformation = function(){
return [
''
, ' Usage: ' + this.name + ' ' + this.usage()
, ' Usage: ' + this._name + ' ' + this.usage()
, '' + this.commandHelp()
, ' Options:'
, ''
Expand Down

0 comments on commit 2e4fe08

Please sign in to comment.