Skip to content

Commit

Permalink
Add interleaved option to "args" module parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Robinson committed Feb 24, 2010
1 parent 9e54a61 commit a36a0a0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ exports.Parser.prototype.check = function () {

// TODO break this into sub-functions
// TODO wrap with a try catch and print the progress through the arguments
exports.Parser.prototype.parse = function (args, options, noCommand) {
exports.Parser.prototype.parse = function (args, options, noCommand, allowInterleaved) {
var self = this;

this.check();
Expand Down Expand Up @@ -375,6 +375,8 @@ exports.Parser.prototype.parse = function (args, options, noCommand) {
options[option.getName()] = option._def;
});

var interleavedArgs = [];

// walk args
ARGS: while (args.length) {
var arg = args.shift();
Expand Down Expand Up @@ -464,15 +466,16 @@ exports.Parser.prototype.parse = function (args, options, noCommand) {
}

} else {
// TODO permit options interleaved with arguments,
// with associated actions, for any of positional
// args, variadic args, and accumulated args
args.unshift(arg);
break;
interleavedArgs.push(arg);
if (!allowInterleaved)
break;
}

}

// add the interleaved arguments back in
args.unshift.apply(args, interleavedArgs)

if (util.len(this._commands)) {
if (args.length) {
if (util.has(this._commands, args[0])) {
Expand Down

0 comments on commit a36a0a0

Please sign in to comment.