Blame view

node_modules/bower/lib/util/cli.js 1.21 KB
2dda2e10   Administrator   generator ignore
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
  var mout = require('mout');
  var nopt = require('nopt');
  var renderers = require('../renderers');
  
  function readOptions(options, argv) {
      var types;
      var noptOptions;
      var parsedOptions = {};
      var shorthands = {};
  
      if (Array.isArray(options)) {
          argv = options;
          options = {};
      } else {
          options = options || {};
      }
  
      types = mout.object.map(options, function (option) {
          return option.type;
      });
      mout.object.forOwn(options, function (option, name) {
          shorthands[option.shorthand] = '--' + name;
      });
  
      noptOptions = nopt(types, shorthands, argv);
  
      // Filter only the specified options because nopt parses every --
      // Also make them camel case
      mout.object.forOwn(noptOptions, function (value, key) {
          if (options[key]) {
              parsedOptions[mout.string.camelCase(key)] = value;
          }
      });
  
      parsedOptions.argv = noptOptions.argv;
  
      return parsedOptions;
  }
  
  function getRenderer(command, json, config) {
      if (config.json || json) {
          return new renderers.Json(command, config);
      }
  
      return new renderers.Standard(command, config);
  }
  
  module.exports.readOptions = readOptions;
  module.exports.getRenderer = getRenderer;