cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [5/7] cordova-cli git commit: CB-11982 : added edit and ls to delete command
Date Thu, 20 Apr 2017 00:21:25 GMT
CB-11982 : added edit and ls to delete command


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

Branch: refs/heads/master
Commit: 7c035ce1ba73f416498d9ee926ac53dcc4888a10
Parents: c6286f2
Author: Audrey So <audreyso@apache.org>
Authored: Thu Feb 2 16:39:39 2017 -0800
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Wed Apr 19 14:34:53 2017 -0700

----------------------------------------------------------------------
 doc/config.txt   |  2 ++
 package.json     |  1 +
 spec/cli.spec.js | 23 ++++++++++++++++++++++-
 src/cli.js       | 43 ++++++++++++++++++++++++++++++++++++-------
 4 files changed, 61 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7c035ce1/doc/config.txt
----------------------------------------------------------------------
diff --git a/doc/config.txt b/doc/config.txt
index 2861ac7..f79b41b 100644
--- a/doc/config.txt
+++ b/doc/config.txt
@@ -11,6 +11,7 @@ Options
 --get <key> ...................................... Echo the config value to 						
											   stdout.
 --delete <key> ................................... Deletes the key from all 						
											   configuration files.
 --edit ........................................... Opens the config file in an 									
								   editor.
+--ls ............................................. Lists contents of config file.
 
 Example
 
@@ -18,3 +19,4 @@ cordova-cli config set <key> <value> --> cordova config set
autosave true
 cordova-cli config get <key> 		 --> cordova config get autosave
 cordova-cli config delete <key>		 --> cordova config delete autosave
 cordova-cli config edit 			 --> cordova config edit
+cordova-cli config ls 				 --> cordova config ls

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7c035ce1/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 57f5108..50976e1 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
     "configstore": "2.1.0",
     "cordova-common": "2.0.2",
     "cordova-lib": "6.5.0",
+    "editor": "1.0.0",
     "insight": "0.8.2",
     "nopt": "3.0.1",
     "q": "1.0.1",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7c035ce1/spec/cli.spec.js
----------------------------------------------------------------------
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index 849f086..e01a291 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -456,8 +456,29 @@ describe("platform", function () {
             done();
         });
     });
-});
 
+    it("Test #044 : config edit is called", function (done) {
+        cli(["node", "cordova", "config", "edit"], function () {
+            expect(cordova.raw.config).toHaveBeenCalledWith(
+                'edit',
+                [ ],
+                jasmine.any(Object)
+            );
+            done();
+        });
+    });
+
+    it("Test #045 : config edit is called", function (done) {
+        cli(["node", "cordova", "config", "ls"], function () {
+            expect(cordova.raw.config).toHaveBeenCalledWith(
+                'ls',
+                [ ],
+                jasmine.any(Object)
+            );
+            done();
+        });
+    });
+});
 describe("config", function () {
     beforeEach(function () {
         spyOn(cordova.raw, "config").and.returnValue(Q());

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7c035ce1/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index f52a51f..16265cd 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -34,8 +34,11 @@ var path = require('path'),
     CordovaError = cordova_lib.CordovaError,
     cordova = cordova_lib.cordova,
     events = cordova_lib.events,
-    logger = require('cordova-common').CordovaLogger.get();
-
+    logger = require('cordova-common').CordovaLogger.get(),
+    Configstore = require('configstore'),
+    conf = new Configstore(pkg.name + '-config'),
+    editor = require('editor'),
+    fs = require('fs');
 
 var knownOpts = {
     'verbose' : Boolean
@@ -125,12 +128,21 @@ module.exports = function (inputArgs, cb) {
     // Q.then is here or after this?
     Q().then(function() {
 
-    // If get is called
+    // If "get" is called
+
     if (isConfigCmd && inputArgs[3] === 'get') {
-        conf.get(inputArgs[4]);
+        if (inputArgs[4]) {
+            logger.subscribe(events);
+            conf.get(inputArgs[4]);
+            if(conf.get(inputArgs[4]) !== undefined) {
+                events.emit('log', conf.get(inputArgs[4]).toString());
+            } else {
+                events.emit('log', 'undefined');
+            }
+        }
     }
 
-    // If set is called
+    // If "set" is called
     if (isConfigCmd && inputArgs[3] === 'set') {
         if (inputArgs[5] === undefined) {
             conf.set(inputArgs[4], true);
@@ -141,13 +153,30 @@ module.exports = function (inputArgs, cb) {
         }
     }
 
-    // If delete is called
+    // If "delete" is called
     if (isConfigCmd && inputArgs[3] === 'delete') {
         if (inputArgs[4]) {
             conf.del(inputArgs[4]);
         }
     }
-    // or should q.then be here?
+
+    // If "edit" is called
+    if (isConfigCmd && inputArgs[3] === 'edit') {
+        editor(conf.path, function (code, sig) {
+            console.log('Finished editing with code ' + code);
+        });
+    }
+
+    // If "ls" is called
+    if (isConfigCmd && inputArgs[3] === 'ls' || inputArgs[3] === 'list') {
+        fs.readFile(conf.path, 'utf8', function (err,data) {
+          if (err) {
+            return console.log(err);
+          }
+          console.log(data);
+        });
+    }
+    
     Q().then(function() {
         /**
          * Skip telemetry prompt if:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message