Updated Branches:
  refs/heads/master2 c56c0b90b -> cda104f6d

[CB-3791] Provide correct error message is plugin/platform add/rm is called 
with no targets


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

Branch: refs/heads/master2
Commit: cda104f6d65cb236fae84a1fc07158010295a531
Parents: c56c0b9
Author: Fil Maj <[email protected]>
Authored: Thu Jun 13 12:00:06 2013 -0700
Committer: Fil Maj <[email protected]>
Committed: Thu Jun 13 12:00:06 2013 -0700

----------------------------------------------------------------------
 spec/platform.spec.js | 10 ++++++++++
 spec/plugin.spec.js   | 10 ++++++++++
 src/platform.js       |  6 ++++++
 src/plugin.js         | 13 +++++++++++--
 4 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cda104f6/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index 132c308..3ea285a 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -78,6 +78,16 @@ describe('platform command', function() {
                 expect(is_cordova).toHaveBeenCalled();
             }).toThrow('Current working directory is not a Cordova-based 
project.');
         });
+        it('should report back an error if used with `add` and no platform is 
specified', function() {
+            expect(function() {
+               cordova.platform('add');
+            }).toThrow('You need to qualify `add` or `remove` with one or more 
platforms!');
+        });
+        it('should report back an error if used with `rm` and no platform is 
specified', function() {
+            expect(function() {
+               cordova.platform('rm');
+            }).toThrow('You need to qualify `add` or `remove` with one or more 
platforms!');
+        });
     });
 
     describe('success', function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cda104f6/spec/plugin.spec.js
----------------------------------------------------------------------
diff --git a/spec/plugin.spec.js b/spec/plugin.spec.js
index 737a846..f340151 100644
--- a/spec/plugin.spec.js
+++ b/spec/plugin.spec.js
@@ -72,6 +72,16 @@ describe('plugin command', function() {
                 expect(is_cordova).toHaveBeenCalled();
             }).toThrow('Current working directory is not a Cordova-based 
project.');
         });
+        it('should report back an error if used with `add` and no plugin is 
specified', function() {
+            expect(function() {
+               cordova.plugin('add');
+            }).toThrow('You need to qualify `add` or `remove` with one or more 
plugins!');
+        });
+        it('should report back an error if used with `rm` and no plugin is 
specified', function() {
+            expect(function() {
+               cordova.plugin('rm');
+            }).toThrow('You need to qualify `add` or `remove` with one or more 
plugins!');
+        });
     });
 
     describe('success', function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cda104f6/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 66cc528..62bf05e 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -52,6 +52,12 @@ module.exports = function platform(command, targets, 
callback) {
                 else throw err;
             }
         });
+    } else {
+        if (command == 'add' || command == 'rm') {
+            var err = new Error('You need to qualify `add` or `remove` with 
one or more platforms!');
+            if (callback) return callback(err);
+            else throw err;
+        }
     }
 
     var xml = cordova_util.projectConfig(projectRoot);

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cda104f6/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index 38e0359..52bd2c8 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -45,9 +45,18 @@ module.exports = function plugin(command, targets, callback) 
{
     var pluginPath, plugins;
     pluginPath = path.join(projectRoot, 'plugins');
     plugins = cordova_util.findPlugins(pluginPath);
-    if (targets && !(targets instanceof Array)) {
-        targets = [targets];
+    if (targets) {
+        if (!(targets instanceof Array)) {
+            targets = [targets];
+        }
+    } else {
+        if (command == 'add' || command == 'rm') {
+            var err = new Error('You need to qualify `add` or `remove` with 
one or more plugins!');
+            if (callback) return callback(err);
+            else throw err;
+        }
     }
+
     var opts = {
         plugins:targets
     };

Reply via email to