UNPKG

952 BJavaScriptView Raw
1/*
2 * grunt
3 * https://github.com/cowboy/grunt
4 *
5 * Copyright (c) 2012 "Cowboy" Ben Alman
6 * Licensed under the MIT license.
7 * http://benalman.com/about/license/
8 */
9
10// The actual option data.
11var data = {};
12
13// Get or set an option value.
14var option = module.exports = function(key, value) {
15 var no = key.match(/^no-(.+)$/);
16 if (arguments.length === 2) {
17 return (data[key] = value);
18 } else if (no) {
19 return data[no[1]] === false;
20 } else {
21 return data[key];
22 }
23};
24
25// Initialize option data.
26option.init = function(obj) {
27 return (data = obj || {});
28};
29
30// List of options as flags.
31option.flags = function() {
32 return Object.keys(data).filter(function(key) {
33 // Don't display empty arrays.
34 return !(Array.isArray(data[key]) && data[key].length === 0);
35 }).map(function(key) {
36 var val = data[key];
37 return '--' + (val === false ? 'no-' : '') + key +
38 (typeof val === 'boolean' ? '' : '=' + val);
39 });
40};