You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/07/31 02:01:29 UTC

git commit: bumped to plugman 0.10.0. added optimist. refactored cli shim into own module.

Updated Branches:
  refs/heads/passThrough 6cf923ae4 -> f96cc3245


bumped to plugman 0.10.0. added optimist. refactored cli shim into own module.


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/f96cc324
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/f96cc324
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/f96cc324

Branch: refs/heads/passThrough
Commit: f96cc3245771ab753ae0d584bd254d505e34f13f
Parents: 6cf923a
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Jul 30 17:01:23 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Tue Jul 30 17:01:23 2013 -0700

----------------------------------------------------------------------
 bin/cordova  | 68 ++--------------------------------------------------
 package.json |  5 ++--
 src/cli.js   | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f96cc324/bin/cordova
----------------------------------------------------------------------
diff --git a/bin/cordova b/bin/cordova
index 63a3a90..4b0c4de 100755
--- a/bin/cordova
+++ b/bin/cordova
@@ -1,68 +1,4 @@
 #!/usr/bin/env node
-var tokens = process.argv.slice(2, process.argv.length),
-    cordova= require('../cordova'),
-    plugman= require('plugman'),
-    platforms= require("../platforms"),
-    opts = {
-        platforms: [],
-        options: [],
-        verbose: false
-    },
-    cmd,
-    version = false,
-    current;
+var CLI = require('../src/cli');
 
-while (current = tokens.shift()) {
-    if (current[0] == '-') {
-        if (current.indexOf('version') > -1 || current[1] == 'v') version = true;
-        if (current.indexOf('verbose') > -1 || current[1] == 'd') opts.verbose = true;
-    } else {
-        cmd = current;
-        break;
-    }
-}
-
-// provide clean output on exceptions rather than dumping a stack trace
-process.on('uncaughtException', function(err){
-    if (opts.verbose) {
-        console.error(err.stack);
-    } else {
-        console.error(err);
-    }
-    process.exit(1);
-});
-cordova.on('results', console.log);
-
-if (opts.verbose) {
-    cordova.on('log', console.log);
-    cordova.on('warn', console.warn);
-    plugman.on('log', console.log);
-    plugman.on('warn', console.warn);
-}
-
-if (version) {
-    console.log(require('../package').version);
-} else if (cmd === undefined) {
-    cordova.help();
-} else if (cordova.hasOwnProperty(cmd)) {
-    if (cmd == 'create' || cmd == 'serve') {
-        opts = Array.prototype.slice.call(tokens, 0);
-        cordova[cmd].apply(this, opts);
-    } else if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run') {
-        //Filter all non-platforms into options
-        Array.prototype.slice.call(tokens, 0).forEach(function(option, index) {
-            if (platforms.hasOwnProperty(option)) {
-                opts.platforms.push(option);
-            } else {
-                opts.options.push(option);
-            }
-        });
-        cordova[cmd].call(this, opts);
-    } else {
-        // platform or plugin cmds
-        opts = Array.prototype.slice.call(tokens, 0);
-        cordova[cmd].apply(this, opts);
-    }
-} else {
-    throw new Error('Cordova does not know ' + cmd + '; try help for a list of all the available commands.');
-}
+new CLI(process.argv);

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f96cc324/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index c1c7509..8e2d31c 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,7 @@
   "dependencies": {
     "colors":">=0.6.0",
     "elementtree":"0.1.3",
-    "plugman":"0.9.23",
+    "plugman":"0.10.0",
     "plist":"0.4.x",
     "xcode":"0.5.1",
     "express":"3.0.0",
@@ -44,7 +44,8 @@
     "prompt":"0.2.7",
     "tar":"0.1.x",
     "open": "0.0.3",
-    "npm":"1.3.x"
+    "npm":"1.3.x",
+    "optimist":"0.6.0"
   },
   "devDependencies": {
     "jasmine-node":"1.8.x"

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f96cc324/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
new file mode 100755
index 0000000..16c818c
--- /dev/null
+++ b/src/cli.js
@@ -0,0 +1,72 @@
+var optimist  = require('optimist'),
+    cordova   = require('../cordova'),
+    plugman   = require('plugman'),
+    platforms = require("../platforms");
+
+module.exports = function CLI(args) {
+    args = optimist(args)
+        .boolean('d')
+        .boolean('verbose')
+        .boolean('v')
+        .boolean('version')
+        .argv;
+
+    if (args.v || args.version) {
+        return console.log(require('../package').version);
+    }
+
+    var tokens = args._.slice(2),
+        opts = {
+            platforms: [],
+            options: [],
+            verbose: (args.d || args.verbose)
+        },
+        cmd = tokens && tokens.length ? tokens[0] : undefined;
+
+    // provide clean output on exceptions rather than dumping a stack trace
+    process.on('uncaughtException', function(err){
+        if (opts.verbose) {
+            console.error(err.stack);
+        } else {
+            console.error(err);
+        }
+        process.exit(1);
+    });
+    cordova.on('results', console.log);
+
+    if (opts.verbose) {
+        cordova.on('log', console.log);
+        cordova.on('warn', console.warn);
+        plugman.on('log', console.log);
+        plugman.on('warn', console.warn);
+    }
+
+    if (cmd === undefined) {
+        return cordova.help();
+    }
+
+    tokens = tokens.slice(1);
+    if (cordova.hasOwnProperty(cmd)) {
+        if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run') {
+            // Filter all non-platforms into options
+            tokens.forEach(function(option, index) {
+                if (platforms.hasOwnProperty(option)) {
+                    opts.platforms.push(option);
+                } else {
+                    opts.options.push(option);
+                }
+            });
+            cordova[cmd].call(this, opts);
+        } else if (cmd == 'create' || cmd == 'serve') {
+            cordova[cmd].apply(this, tokens);
+        } else {
+            // platform/plugins add/rm [target(s)]
+            var invocation = tokens.slice(0,1); // this has the sub-command, i.e. "platform add" or "plugin rm"
+            var targets = tokens.slice(1); // this should be an array of targets, be it platforms or plugins
+            invocation.push(targets);
+            cordova[cmd].apply(this, invocation);
+        }
+    } else {
+        throw new Error('Cordova does not know ' + cmd + '; try help for a list of all the available commands.');
+    }
+}