forked from acuminous/bosco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
67 lines (53 loc) · 1.95 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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;