UNPKG

1.37 kBJavaScriptView Raw
1var common = require('./common');
2
3common.register('set', _set, {
4 allowGlobbing: false,
5 wrapOutput: false,
6});
7
8//@
9//@ ### set(options)
10//@ Available options:
11//@
12//@ + `+/-e`: exit upon error (`config.fatal`)
13//@ + `+/-v`: verbose: show all commands (`config.verbose`)
14//@ + `+/-f`: disable filename expansion (globbing)
15//@
16//@ Examples:
17//@
18//@ ```javascript
19//@ set('-e'); // exit upon first error
20//@ set('+e'); // this undoes a "set('-e')"
21//@ ```
22//@
23//@ Sets global configuration variables
24function _set(options) {
25 if (!options) {
26 var args = [].slice.call(arguments, 0);
27 if (args.length < 2) common.error('must provide an argument');
28 options = args[1];
29 }
30 var negate = (options[0] === '+');
31 if (negate) {
32 options = '-' + options.slice(1); // parseOptions needs a '-' prefix
33 }
34 options = common.parseOptions(options, {
35 'e': 'fatal',
36 'v': 'verbose',
37 'f': 'noglob',
38 });
39
40 if (negate) {
41 Object.keys(options).forEach(function (key) {
42 options[key] = !options[key];
43 });
44 }
45
46 Object.keys(options).forEach(function (key) {
47 // Only change the global config if `negate` is false and the option is true
48 // or if `negate` is true and the option is false (aka negate !== option)
49 if (negate !== options[key]) {
50 common.config[key] = options[key];
51 }
52 });
53 return;
54}
55module.exports = _set;