lib/extern/optparse/lib/optparse.js
function(args) {
        var result = [], callback;
        var rules = build_rules(this.filters, this._rules);
        var tokens = args.concat([]);
        var token;
        while(this._halt == false && (token = tokens.shift())) {
            if(LONG_SWITCH_RE.test(token) || SHORT_SWITCH_RE.test(token)) {
                var arg = undefined;
                // The token is a long or a short switch. Get the corresponding
                // rule, filter and handle it. Pass the switch to the default
                // handler if no rule matched.
                for(var i = 0; i < rules.length; i++) {
                    var rule = rules[i];
                    if(rule.long == token || rule.short == token) {
                        if(rule.filter !== undefined) {
                            arg = tokens.shift();
                            if(!LONG_SWITCH_RE.test(arg) && !SHORT_SWITCH_RE.test(arg)) {
                                try {
                                    arg = rule.filter(arg);
                                } catch(e) {
                                    throw OptError(token + ': ' + e.toString());
                                }
                            } else if(rule.optional_arg) {
                                tokens.unshift(arg);
                            } else {
                                throw OptError('Expected switch argument.');
                            }
                        }
                        callback = this.on_switches[rule.name];
                        if (!callback) callback = this.on_switches['*'];
                        if(callback) callback.apply(this, [rule.name, arg]);
                        break;
                    }
                }
                if(i == rules.length) this.default_handler.apply(this, [token]);
            } else {
                // Did not match long or short switch. Parse the token as a
                // normal argument.
                callback = this.on_args[result.length];
                result.push(token);
                if(callback) callback.apply(this, [token]);
            }
        }
        return this._halt ? this.on_halt.apply(this, [tokens]) : result;
    }
function(args) {
        var result = [], callback;
        var rules = build_rules(this.filters, this._rules);
        var tokens = args.concat([]);
        var token;
        while(this._halt == false && (token = tokens.shift())) {
            if(LONG_SWITCH_RE.test(token) || SHORT_SWITCH_RE.test(token)) {
                var arg = undefined;
                // The token is a long or a short switch. Get the corresponding
                // rule, filter and handle it. Pass the switch to the default
                // handler if no rule matched.
                for(var i = 0; i < rules.length; i++) {
                    var rule = rules[i];
                    if(rule.long == token || rule.short == token) {
                        if(rule.filter !== undefined) {
                            arg = tokens.shift();
                            if(!LONG_SWITCH_RE.test(arg) && !SHORT_SWITCH_RE.test(arg)) {
                                try {
                                    arg = rule.filter(arg);
                                } catch(e) {
                                    throw OptError(token + ': ' + e.toString());
                                }
                            } else if(rule.optional_arg) {
                                tokens.unshift(arg);
                            } else {
                                throw OptError('Expected switch argument.');
                            }
                        }
                        callback = this.on_switches[rule.name];
                        if (!callback) callback = this.on_switches['*'];
                        if(callback) callback.apply(this, [rule.name, arg]);
                        break;
                    }
                }
                if(i == rules.length) this.default_handler.apply(this, [token]);
            } else {
                // Did not match long or short switch. Parse the token as a
                // normal argument.
                callback = this.on_args[result.length];
                result.push(token);
                if(callback) callback.apply(this, [token]);
            }
        }
        return this._halt ? this.on_halt.apply(this, [tokens]) : result;
    }
function ( args ) { var result = [ ] , callback ; var rules = build_rules ( this . filters , this . _rules ) ; var tokens = args . concat ( [ ] ) ; var token ; while ( this . _halt == false && ( token = tokens . shift ( ) ) ) { if ( LONG_SWITCH_RE . test ( token ) || SHORT_SWITCH_RE . test ( token ) ) { var arg = undefined ; // The token is a long or a short switch. Get the corresponding // rule, filter and handle it. Pass the switch to the default // handler if no rule matched. for ( var i = 0 ; i < rules . length ; i ++ ) { var rule = rules [ i ] ; if ( rule . long == token || rule . short == token ) { if ( rule . filter !== undefined ) { arg = tokens . shift ( ) ; if ( ! LONG_SWITCH_RE . test ( arg ) && ! SHORT_SWITCH_RE . test ( arg ) ) { try { arg = rule . filter ( arg ) ; } catch ( e ) { throw OptError ( token + ': ' + e . toString ( ) ) ; } } else if ( rule . optional_arg ) { tokens . unshift ( arg ) ; } else { throw OptError ( 'Expected switch argument.' ) ; } } callback = this . on_switches [ rule . name ] ; if ( ! callback ) callback = this . on_switches [ '*' ] ; if ( callback ) callback . apply ( this , [ rule . name , arg ] ) ; break ; } } if ( i == rules . length ) this . default_handler . apply ( this , [ token ] ) ; } else { // Did not match long or short switch. Parse the token as a // normal argument. callback = this . on_args [ result . length ] ; result . push ( token ) ; if ( callback ) callback . apply ( this , [ token ] ) ; } } return this . _halt ? this . on_halt . apply ( this , [ tokens ] ) : result ; }
Parses specified args. Returns remaining arguments.
Parses specified args . Returns remaining arguments .