blob: 238e23e4ab8d544dd032f23c35ead8d4a5e99195 (
plain)
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
|
var common = require('./common');
common.register('set', _set, {
allowGlobbing: false,
wrapOutput: false,
});
//@
//@ ### set(options)
//@ Available options:
//@
//@ + `+/-e`: exit upon error (`config.fatal`)
//@ + `+/-v`: verbose: show all commands (`config.verbose`)
//@ + `+/-f`: disable filename expansion (globbing)
//@
//@ Examples:
//@
//@ ```javascript
//@ set('-e'); // exit upon first error
//@ set('+e'); // this undoes a "set('-e')"
//@ ```
//@
//@ Sets global configuration variables
function _set(options) {
if (!options) {
var args = [].slice.call(arguments, 0);
if (args.length < 2) common.error('must provide an argument');
options = args[1];
}
var negate = (options[0] === '+');
if (negate) {
options = '-' + options.slice(1); // parseOptions needs a '-' prefix
}
options = common.parseOptions(options, {
'e': 'fatal',
'v': 'verbose',
'f': 'noglob',
});
if (negate) {
Object.keys(options).forEach(function (key) {
options[key] = !options[key];
});
}
Object.keys(options).forEach(function (key) {
// Only change the global config if `negate` is false and the option is true
// or if `negate` is true and the option is false (aka negate !== option)
if (negate !== options[key]) {
common.config[key] = options[key];
}
});
return;
}
module.exports = _set;
|