/**
 * Module dependencies.
 */

// var cordovaLinter = require('../cordova-linter.js');

/**
 * Parse command-line arguments.
 *
 * Inspects the arguments and calls the appropriate action.
 *
 * Options:
 *
 *   - `argv` {Object} is an optimist.argv object.
 *   - `[callback]` {Function} is called on completion.
 */

module.exports = function(argv, callback) {
    // optional callback
    callback = callback || function() {};

    // --version
    if (argv.version || argv.v) {
        this.version(argv, callback);
        return;
    }

    // --verbose
    // if (argv.verbose || argv.V) {
    //     cordovaLinter.mode({ verbose: true });
    // }

    // --help
    if (argv.help || argv.h || !argv._.length) {
        this.help(argv, callback);
    }

    // support <command> help
    // if (argv._[argv._.length-1] === 'help' && argv._.length > 1) {
    //     argv._.pop();
    //     argv._.unshift('help');
    // }

    // lookup command to execute
    var command = this;
    for (var i = 0, l = argv._.length; i < l; i++) {
        if (typeof command[argv._[i]] === 'function') {
            command = command[argv._[i]];
        }
        else {
            break;
        }
    }

    // execute command
    if (command === this) {
        this.help(argv, callback);
    }
    else {
        command.call(this, argv, callback);
    }
};

@@ -697,25 +697,8 @@
 v.h 
-%7C%7C !argv._.length
 ) %7B%0A

print help message just once if no arguments sent