cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [2/7] cordova-cli git commit: CB-11982 : added config command that sets, gets, and deletes
Date Thu, 20 Apr 2017 00:21:22 GMT
CB-11982 : added config command that sets, gets, and deletes


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

Branch: refs/heads/master
Commit: dba7c9ab5e80b040da648ac1c6085b5cb8fbf1d6
Parents: 72440d1
Author: Audrey So <audreyso@apache.org>
Authored: Tue Jan 31 15:27:34 2017 -0800
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Wed Apr 19 14:32:51 2017 -0700

----------------------------------------------------------------------
 doc/config.txt | 20 ++++++++++++++++++++
 src/cli.js     | 31 +++++++++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/dba7c9ab/doc/config.txt
----------------------------------------------------------------------
diff --git a/doc/config.txt b/doc/config.txt
new file mode 100644
index 0000000..2861ac7
--- /dev/null
+++ b/doc/config.txt
@@ -0,0 +1,20 @@
+Synopsis
+
+    cordova-cli config <command> [options]
+    
+
+The config command can be used to set, get, delete, and edit the 
+contents of the user files.
+
+Options
+--set <key> <value> .............................. Sets the config key to the
																		   value.If value is omitted, 																		   then it sets it to "true".
+--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.
+
+Example
+
+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

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/dba7c9ab/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index 824942e..f49aa7b 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -76,6 +76,9 @@ var shortHands = {
     ,'t' : '--template'
 };
 
+var Configstore = require('configstore');
+var conf = new Configstore(pkg.name + '-config');
+
 
 function checkForUpdates() {
     try {
@@ -83,7 +86,6 @@ function checkForUpdates() {
         var notifier = updateNotifier({
             pkg: pkg
         });
-
         // Notify using the built-in convenience method
         notifier.notify();
     } catch (e) {
@@ -111,6 +113,7 @@ module.exports = function (inputArgs, cb) {
     var cmd = inputArgs[2]; // e.g: inputArgs= 'node cordova run ios'
     var subcommand = getSubCommand(inputArgs, cmd);
     var isTelemetryCmd = (cmd === 'telemetry');
+    var isConfigCmd = (cmd === 'config');
 
     // ToDO: Move nopt-based parsing of args up here
     if(cmd === '--version' || cmd === '-v') {
@@ -119,8 +122,32 @@ module.exports = function (inputArgs, cb) {
         cmd = 'help';
     }
 
+    // Q.then is here or after this?
     Q().then(function() {
 
+    // If get is called
+    if (isConfigCmd && inputArgs[3] === 'get') {
+        conf.get(inputArgs[4]);
+    }
+    // If set is called
+    if (isConfigCmd && inputArgs[3] === 'set') {
+        if (inputArgs[5] === undefined) {
+            conf.set(inputArgs[4], null);
+        }
+
+        if(inputArgs[5]) {
+            conf.set(inputArgs[4], inputArgs[5]);
+        }
+    }
+
+    // If delete is called
+    if (isConfigCmd && inputArgs[3] === 'delete') {
+        if (inputArgs[4]) {
+            conf.del(inputArgs[4]);
+        }
+    }
+    // or should q.then be here?
+    Q().then(function() {
         /**
          * Skip telemetry prompt if:
          * - CI environment variable is present
@@ -173,7 +200,7 @@ module.exports = function (inputArgs, cb) {
 };
 
 function getSubCommand(args, cmd) {
-    if(cmd === 'platform' || cmd === 'platforms' || cmd === 'plugin' || cmd === 'plugins'
|| cmd === 'telemetry') {
+    if(cmd === 'platform' || cmd === 'platforms' || cmd === 'plugin' || cmd === 'plugins'
|| cmd === 'telemetry' || cmd === 'config') {
         return args[3]; // e.g: args='node cordova platform rm ios', 'node cordova telemetry
on'
     }
     return null;


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


Mime
View raw message