UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const Logger_1 = require("./Logger");
4class ProcessArgs {
5 constructor(args, node) {
6 this.log = Logger_1.Logger.extend('args');
7 this.log.debug(node, ...args);
8 this.filtered = this.filter(args, node);
9 this.log.debug(this.exe, this.args, this.normalized);
10 }
11 static from(args, node = true) {
12 return new ProcessArgs(args, node);
13 }
14 get args() {
15 return this.filtered;
16 }
17 get argsOnly() {
18 return this.normalized.filter(arg => !arg.startsWith('-'));
19 }
20 get exe() {
21 return this.filtered[0];
22 }
23 get normalized() {
24 return this.filtered.slice(1);
25 }
26 get switches() {
27 return this.normalized.filter(arg => arg.startsWith('-'));
28 }
29 has(...names) {
30 return names.some(name => this.hasOne(name));
31 }
32 hasOne(name) {
33 return this.switches.some(x => this.normalize(x) === this.normalize(name));
34 }
35 filter(args, node) {
36 return node ? args.slice(1) : args;
37 }
38 normalize(name) {
39 const argument = name.startsWith('--') ? name.substring(2) : name.startsWith('-') ? name.substring(1) : name;
40 return argument.trim().toLowerCase();
41 }
42}
43exports.ProcessArgs = ProcessArgs;
44//# sourceMappingURL=ProcessArgs.js.map
\No newline at end of file