1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | var Logger_1 = __importDefault(require("./Logger"));
|
7 | var ProcessArgs = (function () {
|
8 | function ProcessArgs(args, node) {
|
9 | var _a;
|
10 | this.log = Logger_1.default.extend('args');
|
11 | (_a = this.log).debug.apply(_a, [node].concat(args));
|
12 | this.filtered = this.filter(args, node);
|
13 | this.log.debug(this.exe, this.args, this.normalized);
|
14 | }
|
15 | ProcessArgs.from = function (args, node) {
|
16 | if (node === void 0) { node = true; }
|
17 | return new ProcessArgs(args, node);
|
18 | };
|
19 | Object.defineProperty(ProcessArgs.prototype, "args", {
|
20 | get: function () {
|
21 | return this.filtered;
|
22 | },
|
23 | enumerable: true,
|
24 | configurable: true
|
25 | });
|
26 | Object.defineProperty(ProcessArgs.prototype, "argsOnly", {
|
27 | get: function () {
|
28 | return this.normalized.filter(function (arg) { return !arg.startsWith('-'); });
|
29 | },
|
30 | enumerable: true,
|
31 | configurable: true
|
32 | });
|
33 | Object.defineProperty(ProcessArgs.prototype, "exe", {
|
34 | get: function () {
|
35 | return this.filtered[0];
|
36 | },
|
37 | enumerable: true,
|
38 | configurable: true
|
39 | });
|
40 | Object.defineProperty(ProcessArgs.prototype, "normalized", {
|
41 | get: function () {
|
42 | return this.filtered.slice(1);
|
43 | },
|
44 | enumerable: true,
|
45 | configurable: true
|
46 | });
|
47 | Object.defineProperty(ProcessArgs.prototype, "switches", {
|
48 | get: function () {
|
49 | return this.normalized.filter(function (arg) { return arg.startsWith('-'); });
|
50 | },
|
51 | enumerable: true,
|
52 | configurable: true
|
53 | });
|
54 | ProcessArgs.prototype.has = function () {
|
55 | var _this = this;
|
56 | var names = [];
|
57 | for (var _i = 0; _i < arguments.length; _i++) {
|
58 | names[_i] = arguments[_i];
|
59 | }
|
60 | return names.some(function (name) { return _this.hasOne(name); });
|
61 | };
|
62 | ProcessArgs.prototype.hasOne = function (name) {
|
63 | var _this = this;
|
64 | return this.switches.some(function (x) { return _this.normalize(x) === _this.normalize(name); });
|
65 | };
|
66 | ProcessArgs.prototype.filter = function (args, node) {
|
67 | return node ? args.slice(1) : args;
|
68 | };
|
69 | ProcessArgs.prototype.normalize = function (name) {
|
70 | var argument = name.startsWith('--') ? name.substring(2) : name.startsWith('-') ? name.substring(1) : name;
|
71 | return argument.trim().toLowerCase();
|
72 | };
|
73 | return ProcessArgs;
|
74 | }());
|
75 | exports.ProcessArgs = ProcessArgs;
|
76 |
|
\ | No newline at end of file |