var _ = require('lodash');
var prettyjson = require('prettyjson');

module.exports = {
  name: 'config',
  description: 'Lets you manage config from the command line instead of editing json files',
  usage: 'set <key> <value> | get <key>',
};

function cmd(bosco, args) {
  var type = args.shift();
  var key = args.shift();
  var value = args.shift();

  if (type !== 'set' && type !== 'get') {
    bosco.error('The command needs to be of the format: ' + ('bosco config ' + module.exports.usage).blue);
  }

  function logConfig(config) {
    bosco.console.log(prettyjson.render(config, {noColor: false}));
    bosco.console.log('');
  }

  if (type === 'get') {
    // Get the key
    if (!key) {
      bosco.console.log('');

      bosco.console.log('Config for ' + 'github'.green + ':');
      var github = _.clone(bosco.config.get('github'));
      delete github.repos;
      delete github.ignoredRepos;
      logConfig(github);

      bosco.console.log('Config for ' + 'aws'.green + ':');
      var aws = bosco.config.get('aws');
      logConfig(aws ? aws : 'Not defined');

      bosco.console.log('Config for ' + 'js'.green + ':');
      logConfig(bosco.config.get('js'));

      bosco.console.log('Config for ' + 'css'.green + ':');
      logConfig(bosco.config.get('css'));
    } else {
      bosco.log('Config for ' + key.green + ':');
      logConfig(bosco.config.get(key));
    }
  }

  if (type === 'set') {
    if (!key && !value) return bosco.error('You need to specify a key and value: ' + 'bosco config set <key> <value>'.blue);

    var prevValue = bosco.config.get(key);

    if (typeof prevValue === 'object') {
      return bosco.error('You can only set values, not objects, try one of its children using \':\' as the separator - e.g. github:team');
    }

    bosco.log('Changing ' + key + ' from ' + prevValue + ' to ' + value);
    bosco.config.set(key, value);
    bosco.config.save(function() {
      bosco.log('Saved config');
    });
  }
}

module.exports.cmd = cmd;

@@ -201,16 +201,28 @@
 usage: '
+get %3Ckey%3E %7C 
 set %3Ckey
@@ -233,19 +233,21 @@
 alue%3E %7C 
-get
+clear
  %3Ckey%3E',
@@ -364,162 +364,24 @@
 ();%0A
-%0A
   
-if (type !== 'set' && type !== 'get') %7B%0A    bosco.error('The command needs to be of the format: ' + ('bosco config ' + module.exports.usage).blue);%0A  %7D
+var prevValue;
 %0A%0A  
@@ -515,34 +515,57 @@
 %0A%0A  
-if (type === 'get'
+switch (type) %7B%0A  case 'get':%0A    if (key
 ) %7B%0A    
 // G
@@ -564,41 +564,299 @@
     
+ 
-// Get the key%0A    if (!key) %7B%0A  
+ value = bosco.config.get(key);%0A      if (typeof value === 'undefined') %7B%0A        bosco.log('No config found for ' + key.green);%0A      %7D else %7B%0A        bosco.log('Config for ' + key.green + ':');%0A        logConfig(value);%0A      %7D%0A      break;%0A    %7D%0A%0A    // Show various interesting configs%0A
     
@@ -875,26 +875,24 @@
 e.log('');%0A%0A
-  
     bosco.co
@@ -940,26 +940,24 @@
 + ':');%0A    
- 
- 
 var github =
@@ -994,26 +994,24 @@
 hub'));%0A    
-  
 delete githu
@@ -1015,26 +1015,24 @@
 thub.repos;%0A
-  
     delete g
@@ -1051,26 +1051,24 @@
 dRepos;%0A    
-  
 logConfig(gi
@@ -1071,26 +1071,24 @@
 g(github);%0A%0A
-  
     bosco.co
@@ -1137,18 +1137,16 @@
 ');%0A    
- 
- 
 var aws 
@@ -1168,26 +1168,24 @@
 get('aws');%0A
-  
     logConfi
@@ -1211,34 +1211,32 @@
 defined');%0A%0A    
- 
- 
 bosco.console.lo
@@ -1268,34 +1268,32 @@
 een + ':');%0A    
-  
 logConfig(bosco.
@@ -1312,18 +1312,16 @@
 js'));%0A%0A
-  
     bosc
@@ -1366,34 +1366,32 @@
 een + ':');%0A    
-  
 logConfig(bosco.
@@ -1418,141 +1418,28 @@
     
-%7D else %7B%0A      bosco.log('Config for ' + key.green + ':');%0A      logConfig(bosco.config.get(key));%0A    %7D%0A  %7D%0A%0A  if (type ===
+break;%0A  case
  'set'
-) %7B
+:
 %0A   
@@ -1565,20 +1565,16 @@
 );%0A%0A    
-var 
 prevValu
@@ -1892,32 +1892,39 @@
 ey, value);%0A    
+return 
 bosco.config.sav
@@ -1979,16 +1979,475 @@
     %7D);%0A
+  case 'clear':%0A    if (!key) return bosco.error('You need to specify a key: ' + 'bosco config clear %3Ckey%3E'.blue);%0A%0A    prevValue = bosco.config.get(key);%0A%0A    bosco.log('Clearing ' + key + ' of value ' + prevValue);%0A    bosco.config.clear(key);%0A    return bosco.config.save(function() %7B%0A      bosco.log('Saved config');%0A    %7D);%0A  default:%0A    bosco.error('The command needs to be of the format: ' + ('bosco config ' + module.exports.usage).blue);%0A    break;%0A
   %7D%0A%7D%0A%0Am

Add bosco config clear <key>. and bosco get deals with unset keys