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