aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/ibrik/lib/command.js
blob: 2721cf128469ba9c530c4cb542b409523739872e (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
56
57
// Generated by CoffeeScript 1.8.0
(function() {
  var COMMANDS, TAB, argv, c, command, fs, optimist, possibilities,
    __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

  fs = require('fs');

  optimist = require('optimist');

  COMMANDS = ['cover', 'report'];

  TAB = '        ';

  argv = optimist.usage("Usage: $0 subcommand\n=== subcommands ===\n" + TAB + (COMMANDS.join("\n" + TAB))).argv;

  command = argv._[0];

  if (command == null) {
    optimist.showHelp();
    process.exit(0);
  }

  if (__indexOf.call(COMMANDS, command) < 0) {
    possibilities = (function() {
      var _i, _len, _results;
      _results = [];
      for (_i = 0, _len = COMMANDS.length; _i < _len; _i++) {
        c = COMMANDS[_i];
        if (command === c.slice(0, command.length)) {
          _results.push(c);
        }
      }
      return _results;
    })();
    switch (possibilities.length) {
      case 0:
        console.error("Unrecognised command: `" + command + "`. Run `" + argv['$0'] + "` for help.");
        process.exit(1);
        break;
      case 1:
        command = possibilities[0];
        break;
      default:
        console.error("Ambiguous command `" + command + "` matches `" + (possibilities.join('`, `')) + "`");
        process.exit(1);
    }
  }

  (require("./" + command))(argv, function(err) {
    if (err) {
      console.error(err);
      process.exit(1);
    }
    return process.exit(0);
  });

}).call(this);