Skip to content

Commit

Permalink
.alias()
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 14, 2011
1 parent 4a2065d commit d0c0174
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function Argv (args, cwd) {
else {
self.argv[key] = value;
}

if (aliases[key]) {
self.argv[aliases[key]] = self.argv[key];
}
}

var flags = { bools : {}, strings : {} };
Expand Down Expand Up @@ -87,6 +91,20 @@ function Argv (args, cwd) {
return self;
};

var aliases = {};
self.alias = function (x, y) {
if (typeof x === 'object') {
Object.keys(x).forEach(function (key) {
aliases[key] = x[key];
aliases[x[key]] = key;
});
}
else {
aliases[x] = y;
aliases[y] = x;
}
};

function rescan () {
self.argv = { _ : [], $0 : self.$0 };

Expand Down Expand Up @@ -333,13 +351,13 @@ function Argv (args, cwd) {
default: o.default
};
})

padding = padding || 2;

var larg = longestElement(help.map(function (h) { return h.args })),
described = help.filter(function (h) { return h.description }),
more = help.filter(function (h) { return !h.description });

var larg = longestElement(help.map(function (h) { return h.args }));
var described = help.filter(function (h) { return h.description });
var more = help.filter(function (h) { return !h.description });
function printOpt (h) {
var hdesc = h.description || '';

Expand Down

0 comments on commit d0c0174

Please sign in to comment.