cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject git commit: updated cli interface
Date Wed, 17 Jul 2013 00:19:14 GMT
Updated Branches:
  refs/heads/plugman-registry 8dd5a1b7c -> 241031d26


updated cli interface


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

Branch: refs/heads/plugman-registry
Commit: 241031d26b6d15c520c568bbbcbce97665100248
Parents: 8dd5a1b
Author: Anis Kadri <anis@apache.org>
Authored: Tue Jul 16 17:18:56 2013 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Tue Jul 16 17:18:56 2013 -0700

----------------------------------------------------------------------
 doc/help.txt | 20 ++++++++------
 main.js      | 64 +++++++++----------------------------------
 plugman.js   | 81 ++++++++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 91 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/241031d2/doc/help.txt
----------------------------------------------------------------------
diff --git a/doc/help.txt b/doc/help.txt
index e59d4fa..ae90cd7 100644
--- a/doc/help.txt
+++ b/doc/help.txt
@@ -1,4 +1,4 @@
-plugman installs and uninstalls plugin.xml-compatible cordova plugins into cordova-generated
projects.
+plugman manages plugin.xml-compatible cordova plugins into cordova-generated projects.
 
 Usage
 =====
@@ -6,7 +6,7 @@ Usage
 Install a plugin
 ----------------
 
-    $ plugman --platform <platform> --project <directory> --plugin <plugin>
[--variable NAME=VALUE]
+    $ plugman install --platform <platform> --project <directory> --plugin <plugin>
[--variable NAME=VALUE]
 
 Parameters: 
 
@@ -18,7 +18,7 @@ Parameters:
 Uninstall a plugin
 ------------------
 
-    $ plugman --uninstall --platform <platform> --project <directory> --plugin
<plugin-id>
+    $ plugman uninstall --platform <platform> --project <directory> --plugin
<plugin-id>
 
 Parameters:
  - plugin <plugin-id>: The plugin to remove, identified by its id (see the plugin.xml's
<plugin id> attribute)
@@ -32,7 +32,11 @@ Optional parameters
 Optional flags
 --------------
 
- --debug : Verbose mode
+ --debug|-d    : Verbose mode
+
+ --help|-h     : Displays this message
+
+ --version|-v  : Displays version 
 
 Interacting with the registry
 =============================
@@ -40,20 +44,20 @@ Interacting with the registry
 Add a user account
 ------------------
 
-    $ plugman --adduser
+    $ plugman adduser
 
 Publish a plugin
 ----------------
 
-    $ plugman --publish --plugin <directory>
+    $ plugman publish --plugin <directory>
 
 Unpublish a plugin
 ------------------
 
-    $ plugman --unpublish <name>@<version>
+    $ plugman unpublish <name>@<version>
 
 Search for a plugin
 -------------------
 
-    $ plugman --search plugin,keywords
+    $ plugman search plugin,keywords
 

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/241031d2/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 003ddbc..470db89 100755
--- a/main.js
+++ b/main.js
@@ -29,12 +29,6 @@ var path = require('path')
 var known_opts = { 'platform' : [ 'ios', 'android', 'blackberry10', 'wp7', 'wp8' ]
         , 'project' : path
         , 'plugin' : [String, path, url]
-        , 'install' : Boolean
-        , 'uninstall' : Boolean
-        , 'adduser' : Boolean
-        , 'publish' : Boolean 
-        , 'unpublish' : Boolean 
-        , 'search' : String
         , 'version' : Boolean
         , 'help' : Boolean
         , 'debug' : Boolean
@@ -46,71 +40,39 @@ var known_opts = { 'platform' : [ 'ios', 'android', 'blackberry10', 'wp7',
'wp8'
 
 var cli_opts = nopt(known_opts, shortHands);
 
-// Default the plugins_dir to './cordova/plugins'.
-var plugins_dir;
+var cmd = cli_opts.argv.remain.shift();
 
 // Without these arguments, the commands will fail and print the usage anyway.
 if (cli_opts.plugins_dir || cli_opts.project) {
-    plugins_dir = typeof cli_opts.plugins_dir == 'string' ?
+    cli_opts.plugins_dir = typeof cli_opts.plugins_dir == 'string' ?
         cli_opts.plugins_dir :
         path.join(cli_opts.project, 'cordova', 'plugins');
 }
 
-process.on('uncaughtException', function(error){
-        if (cli_opts.debug) {
+process.on('uncaughtException', function(error) {
+    if (cli_opts.debug) {
         console.error(error.stack);
-        } else {
+    } else {
         console.error(error.message);
-        }
-        process.exit(1);
-        });
+    }
+    process.exit(1);
+});
 
 // Set up appropriate logging based on events
 if (cli_opts.debug) {
     plugman.on('log', console.log);
 }
+
 plugman.on('warn', console.warn);
 plugman.on('error', console.error);
 plugman.on('results', console.log);
+
 if (cli_opts.version) {
     console.log(package.name + ' version ' + package.version);
-} 
-else if (cli_opts.help) {
+} else if (cli_opts.help) {
     console.log(plugman.help());
-}
-else if ((cli_opts.install || cli_opts.uninstall || cli_opts.argv.original.length == 0) &&
(!cli_opts.platform || !cli_opts.project || !cli_opts.plugin)) {
-    console.log(plugman.help());
-}
-else if (cli_opts.uninstall) {
-    plugman.uninstall(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir,
{ www_dir: cli_opts.www });
-}
-else if (cli_opts.adduser) {
-  plugman.adduser();
-}
-else if (cli_opts.publish && cli_opts.plugin) {
-  plugman.publish(new Array(cli_opts.plugin));
-}
-else if (cli_opts.unpublish && cli_opts.plugin) {
-  plugman.unpublish(new Array(cli_opts.plugin));
-}
-else if (cli_opts.search) {
-  plugman.search(cli_opts.search.split(','));
-}
-else if(cli_opts.install) {
-    var cli_variables = {}
-    if (cli_opts.variable) {
-        cli_opts.variable.forEach(function (variable) {
-                var tokens = variable.split('=');
-                var key = tokens.shift().toUpperCase();
-                if (/^[\w-_]+$/.test(key)) cli_variables[key] = tokens.join('=');
-                });
-    }
-    var opts = {
-subdir: '.',
-        cli_variables: cli_variables,
-        www_dir: cli_opts.www
-    };
-    plugman.install(cli_opts.platform, cli_opts.project, cli_opts.plugin, plugins_dir, opts);
+} else if (plugman.commands[cmd]) {
+    plugman.commands[cmd](cli_opts);
 } else {
     console.log(plugman.help());
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/241031d2/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index 541946a..b0dbe03 100755
--- a/plugman.js
+++ b/plugman.js
@@ -21,20 +21,71 @@
 
 var emitter = require('./src/events');
 
-module.exports = {
-    help:           require('./src/help'),
-    install:        require('./src/install'),
-    uninstall:      require('./src/uninstall'),
-    fetch:          require('./src/fetch'),
-    prepare:        require('./src/prepare'),
-    config:         require('./config'), 
-    adduser:  require('./src/adduser'),
-    publish:  require('./src/publish'),
-    unpublish:require('./src/unpublish'),
-    search:   require('./src/search'),
-    config_changes: require('./src/util/config-changes'),
-    on:             emitter.addListener,
-    off:            emitter.removeListener,
+plugman = {
+    help:               require('./src/help'),
+    install:            require('./src/install'),
+    uninstall:          require('./src/uninstall'),
+    fetch:              require('./src/fetch'),
+    prepare:            require('./src/prepare'),
+    config:             require('./config'), 
+    adduser:            require('./src/adduser'),
+    publish:            require('./src/publish'),
+    unpublish:          require('./src/unpublish'),
+    search:             require('./src/search'),
+    config_changes:     require('./src/util/config-changes'),
+    on:                 emitter.addListener,
+    off:                emitter.removeListener,
     removeAllListeners: emitter.removeAllListeners,
-    emit:           emitter.emit
+    emit:               emitter.emit
 };
+
+plugman.commands =  {
+    'install'  : function(cli_opts) {
+        if(!cli_opts.platform || !cli_opts.project || !cli_opts.plugin) {
+            return console.log(plugman.help());
+        }
+        var cli_variables = {}
+        if (cli_opts.variable) {
+            cli_opts.variable.forEach(function (variable) {
+                    var tokens = variable.split('=');
+                    var key = tokens.shift().toUpperCase();
+                    if (/^[\w-_]+$/.test(key)) cli_variables[key] = tokens.join('=');
+                    });
+        }
+        var opts = {
+            subdir: '.',
+            cli_variables: cli_variables,
+            www_dir: cli_opts.www
+        };
+        plugman.install(cli_opts.platform, cli_opts.project, cli_opts.plugin, cli_opts.plugins_dir,
opts);
+    },
+    'uninstall': function(cli_opts) {
+        if(!cli_opts.platform || !cli_opts.project || !cli_opts.plugin) {
+            return console.log(plugman.help());
+        }
+        plugman.uninstall(cli_opts.platform, cli_opts.project, cli_opts.plugin, cli_opts.plugins_dir,
{ www_dir: cli_opts.www });
+    },
+    'adduser'  : function(cli_opts) {
+        plugman.adduser();
+    },
+
+    'search'   : function(cli_opts) {
+        plugman.search(cli_opts.argv.remain);
+    },
+
+    'publish'  : function(cli_opts) {
+        if(!cli_opts.plugin) {
+            return console.log(plugman.help());
+        }
+        plugman.publish(new Array(cli_opts.plugin));
+    },
+
+    'unpublish': function(cli_opts) {
+        if(!cli_opts.plugin) {
+            return console.log(plugman.help());
+        }
+        plugman.unpublish(new Array(cli_opts.plugin));
+    }
+};
+
+module.exports = plugman;


Mime
View raw message