Skip to content

Commit

Permalink
CB-11982 : added config command that sets, gets, and deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyso authored and stevengill committed Apr 19, 2017
1 parent 72440d1 commit dba7c9a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
20 changes: 20 additions & 0 deletions doc/config.txt
Original file line number Diff line number Diff line change
@@ -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
31 changes: 29 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ var shortHands = {
,'t' : '--template'
};

var Configstore = require('configstore');
var conf = new Configstore(pkg.name + '-config');


function checkForUpdates() {
try {
// Checks for available update and returns an instance
var notifier = updateNotifier({
pkg: pkg
});

// Notify using the built-in convenience method
notifier.notify();
} catch (e) {
Expand Down Expand Up @@ -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') {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dba7c9a

Please sign in to comment.