massarg 1.0.7-pre.1 → 2.0.0-pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,693 +1,18 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
4
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
5
- return cooked;
6
- };
7
- var __values = (this && this.__values) || function(o) {
8
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
9
- if (m) return m.call(o);
10
- if (o && typeof o.length === "number") return {
11
- next: function () {
12
- if (o && i >= o.length) o = void 0;
13
- return { value: o && o[i++], done: !o };
14
- }
15
- };
16
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
17
- };
18
- var __read = (this && this.__read) || function (o, n) {
19
- var m = typeof Symbol === "function" && o[Symbol.iterator];
20
- if (!m) return o;
21
- var i = m.call(o), r, ar = [], e;
22
- try {
23
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
7
  }
25
- catch (error) { e = { error: error }; }
26
- finally {
27
- try {
28
- if (r && !r.done && (m = i["return"])) m.call(i);
29
- }
30
- finally { if (e) throw e.error; }
31
- }
32
- return ar;
33
- };
34
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
35
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
36
- if (ar || !(i in from)) {
37
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
38
- ar[i] = from[i];
39
- }
40
- }
41
- return to.concat(ar || Array.prototype.slice.call(from));
42
- };
43
- var __importDefault = (this && this.__importDefault) || function (mod) {
44
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
45
15
  };
46
16
  Object.defineProperty(exports, "__esModule", { value: true });
47
- exports.massarg = exports.Massarg = void 0;
48
- var chalk_1 = __importDefault(require("chalk"));
49
- var merge_1 = __importDefault(require("lodash/merge"));
50
- var camelCase_1 = __importDefault(require("lodash/camelCase"));
51
- var path_1 = __importDefault(require("path"));
52
- var utils_1 = require("./utils");
53
- var errors_1 = require("./errors");
54
- var assertions_1 = require("./assertions");
55
- var Massarg = /** @class */ (function () {
56
- function Massarg() {
57
- this._options = [];
58
- this._commands = [];
59
- this._examples = [];
60
- this._maxNameLen = 0;
61
- /**
62
- * These are the parsed options passed via args. They will only be available after using `parse()` or `printHelp()`,
63
- * or when returned by `parseArgs()`. */
64
- this.data = { help: false, extras: [] };
65
- this._help = {
66
- binName: undefined,
67
- normalColors: "dim",
68
- highlightColors: "yellow",
69
- titleColors: ["bold", "white"],
70
- subtitleColors: ["bold", "dim"],
71
- bodyColors: "white",
72
- printWidth: 80,
73
- header: "",
74
- footer: "",
75
- commandNameSeparator: " | ",
76
- optionNameSeparator: "|",
77
- useGlobalColumns: true,
78
- usageExample: "[command] [options]",
79
- useColors: true,
80
- includeDefaults: true,
81
- exampleInputPrefix: "$",
82
- exampleOutputPrefix: "➜",
83
- };
84
- this._requiredOptions = {};
85
- this.option({
86
- name: "help",
87
- aliases: ["h"],
88
- description: "Display help information",
89
- parse: Boolean,
90
- });
91
- }
92
- /** Define the main command to run when no commands are passed. */
93
- Massarg.prototype.main = function (run) {
94
- (0, assertions_1.assertMain)(run);
95
- this._main = run;
96
- return this;
97
- };
98
- /** Add option to be parsed */
99
- Massarg.prototype.option = function (option) {
100
- var _a, _b, _e;
101
- var defaultValue = option.defaultValue;
102
- // detect boolean values
103
- (_a = option.boolean) !== null && _a !== void 0 ? _a : (option.boolean = option.parse === Boolean || [true, false].includes(defaultValue));
104
- // detect array values
105
- (_b = option.array) !== null && _b !== void 0 ? _b : (option.array = Array.isArray(defaultValue));
106
- // default parser
107
- (_e = option.parse) !== null && _e !== void 0 ? _e : (option.parse = (option.boolean ? this._isTruthy : function (a) { return a; }));
108
- (0, assertions_1.assertOption)(option, this._options);
109
- if (option.array && defaultValue === undefined) {
110
- defaultValue = [];
111
- }
112
- this._options.push(option);
113
- this._prepareRequired(option);
114
- return this;
115
- };
116
- /** Add example line to be added to the help text. */
117
- Massarg.prototype.example = function (example) {
118
- (0, assertions_1.assertExample)(example);
119
- this._examples.push(example);
120
- return this;
121
- };
122
- /** Add command to be run */
123
- Massarg.prototype.command = function (command) {
124
- var e_1, _a;
125
- (0, assertions_1.assertCommand)(command, this._commands);
126
- this._commands.push(command);
127
- try {
128
- for (var _b = __values(this._commandOptions(command)), _e = _b.next(); !_e.done; _e = _b.next()) {
129
- var opt = _e.value;
130
- this._prepareRequired(opt);
131
- }
132
- }
133
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
134
- finally {
135
- try {
136
- if (_e && !_e.done && (_a = _b.return)) _a.call(_b);
137
- }
138
- finally { if (e_1) throw e_1.error; }
139
- }
140
- return this;
141
- };
142
- /** Set options for behavior of the help text print. */
143
- Massarg.prototype.help = function (help) {
144
- (0, assertions_1.assertHelp)(help);
145
- this._help = (0, merge_1.default)(this._help, help);
146
- return this;
147
- };
148
- /**
149
- * Print the help text without being required to pass option.
150
- *
151
- * @param args If args weren't already parsed, you can add them here
152
- */
153
- Massarg.prototype.printHelp = function (args) {
154
- console.log(this.getHelpString(args).join("\n"));
155
- };
156
- /**
157
- * Get the help text as an array of lines. Useful for manipulating the response or querying before displaying
158
- * to the user.
159
- */
160
- Massarg.prototype.getHelpString = function (args) {
161
- var lines = [];
162
- if (args === null || args === void 0 ? void 0 : args.length) {
163
- this.parseArgs(args);
164
- }
165
- var _a = this._help, bodyColors = _a.bodyColors, highlightColors = _a.highlightColors, normalColors = _a.normalColors, titleColors = _a.titleColors, binName = _a.binName, usageExample = _a.usageExample;
166
- lines.push([
167
- this.color(titleColors, "Usage:"),
168
- this.color(highlightColors, binName !== null && binName !== void 0 ? binName : path_1.default.basename(process.argv[1])),
169
- this.color(normalColors, usageExample),
170
- ].join(" "));
171
- lines.push("");
172
- if (this._help.header) {
173
- lines.push(this.color(bodyColors, this._help.header));
174
- lines.push("");
175
- }
176
- if (this._commands.length) {
177
- lines.push(this.color(titleColors, "Commands:"));
178
- lines.push("");
179
- lines.push.apply(lines, __spreadArray([], __read(this._printCommands()), false));
180
- }
181
- lines.push.apply(lines, __spreadArray([], __read(this._printOptions()), false));
182
- if (this._examples.length) {
183
- lines.push(this.color(titleColors, "Examples:"));
184
- lines.push("");
185
- lines.push.apply(lines, __spreadArray([], __read(this._printExamples()), false));
186
- }
187
- if (this._help.footer) {
188
- lines.push(this.color(bodyColors, this._help.footer));
189
- lines.push("");
190
- }
191
- return lines;
192
- };
193
- /**
194
- * Parse the arguments without running the commands related to them. Useful for testing or querying the data from the
195
- * args manually, if it is for some reason not enough to parse it normally through defining commands.
196
- * @param args Arguments to parse. Defaults to `process.argv`
197
- * @returns Parsed options
198
- */
199
- Massarg.prototype.parseArgs = function (args) {
200
- var e_2, _a;
201
- if (args === void 0) { args = process.argv; }
202
- try {
203
- for (var _b = __values(this._options), _e = _b.next(); !_e.done; _e = _b.next()) {
204
- var option = _e.value;
205
- if (option.defaultValue !== undefined) {
206
- this._addOptionToData(option, option.defaultValue);
207
- }
208
- else if (option.array) {
209
- this._pushToArrayData(option);
210
- }
211
- }
212
- }
213
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
214
- finally {
215
- try {
216
- if (_e && !_e.done && (_a = _b.return)) _a.call(_b);
217
- }
218
- finally { if (e_2) throw e_2.error; }
219
- }
220
- var _loop_1 = function (i) {
221
- var e_3, _f;
222
- var arg = args[i];
223
- var option = this_1._options.find(function (o) {
224
- var _a, _b;
225
- // long format
226
- return "--".concat(o.name) === arg ||
227
- // short format - boolean negate
228
- (o.boolean && "--no-".concat(o.name) === arg) ||
229
- (
230
- // short format
231
- (_a = o.aliases) === null || _a === void 0 ? void 0 : _a.map(function (a) { return "-".concat(a); }).includes(arg)) ||
232
- // short format - boolean negate
233
- (o.boolean && ((_b = o.aliases) === null || _b === void 0 ? void 0 : _b.map(function (a) { return "-!".concat(a); }).includes(arg)));
234
- }
235
- //
236
- );
237
- var mightContainDefaultValue = this_1._options.some(function (o) { return o.isDefault; });
238
- if (option) {
239
- var tempValue = void 0;
240
- var hasNextToken = args.length > i + 1;
241
- var nextTokenIsValue = hasNextToken &&
242
- (option.boolean ? mightContainDefaultValue || !args[i + 1].startsWith("-") : !args[i + 1].startsWith("-"));
243
- if (option.boolean && (!hasNextToken || !nextTokenIsValue)) {
244
- // parse boolean args w/o value
245
- tempValue = !arg.replace(/^-+/, "").startsWith("!");
246
- }
247
- else if (!hasNextToken || !nextTokenIsValue) {
248
- // non-boolean args with no value
249
- throw new TypeError("Missing value for: ".concat(option.name));
250
- }
251
- else {
252
- // any args (incl. boolean) with value
253
- tempValue = args[i + 1];
254
- args.shift();
255
- }
256
- var value = option.parse(tempValue, this_1.data);
257
- this_1._addOptionToData(option, value);
258
- // continue
259
- }
260
- var command = this_1._commands.find(function (o) { var _a; return o.name === arg || ((_a = o.aliases) === null || _a === void 0 ? void 0 : _a.includes(arg)); });
261
- var justFoundCommand = false;
262
- if (command) {
263
- if (!this_1._runCommand) {
264
- this_1._runCommand = command;
265
- justFoundCommand = true;
266
- }
267
- }
268
- if (!option && (!command || (command && !justFoundCommand))) {
269
- var defOpts = this_1._options.filter(function (o) { return o.isDefault; });
270
- if (defOpts.length) {
271
- try {
272
- for (var defOpts_1 = (e_3 = void 0, __values(defOpts)), defOpts_1_1 = defOpts_1.next(); !defOpts_1_1.done; defOpts_1_1 = defOpts_1.next()) {
273
- var option_1 = defOpts_1_1.value;
274
- this_1._addOptionToData(option_1, option_1.parse(arg, this_1.data));
275
- }
276
- }
277
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
278
- finally {
279
- try {
280
- if (defOpts_1_1 && !defOpts_1_1.done && (_f = defOpts_1.return)) _f.call(defOpts_1);
281
- }
282
- finally { if (e_3) throw e_3.error; }
283
- }
284
- }
285
- else {
286
- this_1.data.extras.push(arg);
287
- }
288
- }
289
- };
290
- var this_1 = this;
291
- for (var i = 0; i < args.length; i++) {
292
- _loop_1(i);
293
- }
294
- return this.data;
295
- };
296
- /**
297
- * Parse the given args, running any relevant commands in the process.
298
- *
299
- * @param args args to parse. Defaults to `process.argv`
300
- */
301
- Massarg.prototype.parse = function (args) {
302
- this.parseArgs(args);
303
- if (this.data.help) {
304
- this.printHelp();
305
- return;
306
- }
307
- try {
308
- if (this._runCommand) {
309
- this._ensureRequired(this._runCommand);
310
- this._runCommand.run(this.data);
311
- }
312
- else if (this._main) {
313
- this._ensureRequired();
314
- this._main(this.data);
315
- }
316
- else {
317
- this._ensureRequired();
318
- }
319
- }
320
- catch (e) {
321
- if (errors_1.RequiredError.isRequiredError(e)) {
322
- console.error(chalk_1.default.red(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), e.message));
323
- process.exit(1);
324
- }
325
- throw e;
326
- }
327
- return;
328
- };
329
- Massarg.prototype._prepareRequired = function (options) {
330
- var e_4, _a;
331
- var _b, _e, _f;
332
- var _g, _h, _j;
333
- if (options.required) {
334
- if ((_b = options.commands) === null || _b === void 0 ? void 0 : _b.length) {
335
- try {
336
- for (var _k = __values(this._optionCommands(options)), _l = _k.next(); !_l.done; _l = _k.next()) {
337
- var command = _l.value;
338
- (_e = (_g = this._requiredOptions)[_h = command.name]) !== null && _e !== void 0 ? _e : (_g[_h] = {});
339
- this._requiredOptions[command.name][options.name] = true;
340
- }
341
- }
342
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
343
- finally {
344
- try {
345
- if (_l && !_l.done && (_a = _k.return)) _a.call(_k);
346
- }
347
- finally { if (e_4) throw e_4.error; }
348
- }
349
- }
350
- else {
351
- (_f = (_j = this._requiredOptions)["all"]) !== null && _f !== void 0 ? _f : (_j["all"] = {});
352
- this._requiredOptions["all"][options.name] = true;
353
- }
354
- }
355
- };
356
- Massarg.prototype._printExamples = function () {
357
- var e_5, _a;
358
- var lines = [];
359
- var _b = this._help, normalColors = _b.normalColors, highlightColors = _b.highlightColors, bodyColors = _b.bodyColors, titleColors = _b.titleColors;
360
- try {
361
- for (var _e = __values(this._examples), _f = _e.next(); !_f.done; _f = _e.next()) {
362
- var example = _f.value;
363
- if (example.description) {
364
- lines.push.apply(lines, __spreadArray([], __read((0, utils_1.wrap)(this.color(titleColors, example.description), {
365
- colorCount: this.colorCount(titleColors),
366
- indent: 2,
367
- printWidth: this._help.printWidth,
368
- })), false));
369
- lines.push("");
370
- }
371
- lines.push.apply(lines, __spreadArray([], __read((0, utils_1.wrap)([this.color(normalColors, this._help.exampleInputPrefix), this.color(highlightColors, example.input)].join(" "), {
372
- colorCount: this.colorCount(highlightColors),
373
- firstLineIndent: 2,
374
- indent: 3 + this._help.exampleInputPrefix.length,
375
- // indent: this.colorCount(normalColors) + 4,
376
- printWidth: this._help.printWidth,
377
- })), false));
378
- if (example.output) {
379
- lines.push.apply(lines, __spreadArray([], __read((0, utils_1.wrap)([this.color(normalColors, this._help.exampleOutputPrefix), this.color(bodyColors, example.output)].join(" "), {
380
- colorCount: this.colorCount(bodyColors),
381
- firstLineIndent: 2,
382
- indent: 3 + this._help.exampleOutputPrefix.length,
383
- // indent: this.colorCount(normalColors) + 4,
384
- printWidth: this._help.printWidth,
385
- })), false));
386
- }
387
- lines.push("");
388
- }
389
- }
390
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
391
- finally {
392
- try {
393
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
394
- }
395
- finally { if (e_5) throw e_5.error; }
396
- }
397
- return lines;
398
- };
399
- Massarg.prototype._isTruthy = function (v) {
400
- v = String(v).toLowerCase();
401
- return ["1", "true", "yes", "y", "on"].includes(v) || !["0", "false", "no", "n", "off"].includes(v);
402
- };
403
- Massarg.prototype._ensureRequired = function (cmd) {
404
- var _a;
405
- var cmdName = (_a = cmd === null || cmd === void 0 ? void 0 : cmd.name) !== null && _a !== void 0 ? _a : "all";
406
- for (var optName in this._requiredOptions[cmdName]) {
407
- if (this._requiredOptions[cmdName][optName]) {
408
- throw new errors_1.RequiredError(optName, cmdName);
409
- }
410
- }
411
- };
412
- Massarg.prototype._addOptionToData = function (option, value) {
413
- var e_6, _a;
414
- var _this = this;
415
- var _d = this.data;
416
- var set = function (value) {
417
- var _a;
418
- _d[option.name] = value;
419
- _d[(0, camelCase_1.default)(option.name)] = value;
420
- (_a = option.aliases) === null || _a === void 0 ? void 0 : _a.forEach(function (a) { return (_d[a] = value); });
421
- };
422
- var push = function (value) {
423
- _this._pushToArrayData(option, value);
424
- };
425
- if (!option.array) {
426
- // single value
427
- set(value);
428
- }
429
- else {
430
- // multiple values
431
- if (Array.isArray(value) && value.length) {
432
- try {
433
- for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
434
- var el = value_1_1.value;
435
- push(el);
436
- }
437
- }
438
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
439
- finally {
440
- try {
441
- if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
442
- }
443
- finally { if (e_6) throw e_6.error; }
444
- }
445
- }
446
- else if (!Array.isArray(value)) {
447
- push(value);
448
- }
449
- }
450
- if (value !== option.defaultValue && value !== undefined) {
451
- for (var key in this._requiredOptions) {
452
- this._requiredOptions[key][option.name] = false;
453
- }
454
- }
455
- };
456
- Massarg.prototype._pushToArrayData = function (option, value) {
457
- var _a, _b, _e, _f;
458
- var _g, _h;
459
- var _d = this.data;
460
- var ccSame = (0, camelCase_1.default)(option.name) === option.name;
461
- (_a = _d[_g = option.name]) !== null && _a !== void 0 ? _a : (_d[_g] = []);
462
- (_b = _d[_h = (0, camelCase_1.default)(option.name)]) !== null && _b !== void 0 ? _b : (_d[_h] = []);
463
- (_e = option.aliases) === null || _e === void 0 ? void 0 : _e.forEach(function (a) { var _a; return ((_a = _d[a]) !== null && _a !== void 0 ? _a : (_d[a] = [])); });
464
- if (value !== undefined) {
465
- _d[option.name].push(value);
466
- if (!ccSame) {
467
- _d[(0, camelCase_1.default)(option.name)].push(value);
468
- }
469
- (_f = option.aliases) === null || _f === void 0 ? void 0 : _f.forEach(function (a) { return _d[a].push(value); });
470
- }
471
- };
472
- Massarg.prototype._getWrappedLines = function (list) {
473
- var e_7, _a, e_8, _b, e_9, _e;
474
- var _f, _g;
475
- var _h = this._help, normalColors = _h.normalColors, highlightColors = _h.highlightColors;
476
- var lines = [];
477
- var maxNameLen = this._help.useGlobalColumns ? (_f = this._maxNameLen) !== null && _f !== void 0 ? _f : 0 : 0;
478
- try {
479
- for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
480
- var item = list_1_1.value;
481
- if (item.name.length > maxNameLen) {
482
- maxNameLen = item.name.length;
483
- }
484
- }
485
- }
486
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
487
- finally {
488
- try {
489
- if (list_1_1 && !list_1_1.done && (_a = list_1.return)) _a.call(list_1);
490
- }
491
- finally { if (e_7) throw e_7.error; }
492
- }
493
- if (this._help.useGlobalColumns) {
494
- this._maxNameLen = maxNameLen;
495
- }
496
- var ARG_SPACE_LEN = 2;
497
- var INDENT_LEN = 2;
498
- var nameFullSize = maxNameLen + ARG_SPACE_LEN + INDENT_LEN;
499
- try {
500
- for (var list_2 = __values(list), list_2_1 = list_2.next(); !list_2_1.done; list_2_1 = list_2.next()) {
501
- var item = list_2_1.value;
502
- var cmdName = this.color(highlightColors, "".concat(item.name)).padEnd(nameFullSize + this.colorCount(highlightColors) * utils_1.COLOR_CODE_LEN, " ");
503
- var cmdDesc = this.color(normalColors, (_g = item.description) !== null && _g !== void 0 ? _g : "");
504
- try {
505
- for (var _j = (e_9 = void 0, __values((0, utils_1.wrap)(cmdName + cmdDesc, {
506
- indent: nameFullSize + INDENT_LEN,
507
- colorCount: this.colorCount(normalColors, highlightColors, item.additionalColorCount ? new Array({ length: item.additionalColorCount }) : []),
508
- firstLineIndent: INDENT_LEN,
509
- printWidth: this._help.printWidth,
510
- }))), _k = _j.next(); !_k.done; _k = _j.next()) {
511
- var line = _k.value;
512
- lines.push(line);
513
- }
514
- }
515
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
516
- finally {
517
- try {
518
- if (_k && !_k.done && (_e = _j.return)) _e.call(_j);
519
- }
520
- finally { if (e_9) throw e_9.error; }
521
- }
522
- lines.push("");
523
- }
524
- }
525
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
526
- finally {
527
- try {
528
- if (list_2_1 && !list_2_1.done && (_b = list_2.return)) _b.call(list_2);
529
- }
530
- finally { if (e_8) throw e_8.error; }
531
- }
532
- return lines;
533
- };
534
- Massarg.prototype._printCommands = function () {
535
- var _this = this;
536
- return this._getWrappedLines(this._commands.map(function (c) { return ({ name: _this._fullCmdName(c), description: c.description }); }));
537
- };
538
- Massarg.prototype._printOptions = function () {
539
- var e_10, _a, e_11, _b, e_12, _e, e_13, _f;
540
- var _this = this;
541
- var lines = [];
542
- var _g = this._help, titleColors = _g.titleColors, subtitleColors = _g.subtitleColors;
543
- var commandOpts = [];
544
- try {
545
- for (var _h = __values(this._commands), _j = _h.next(); !_j.done; _j = _h.next()) {
546
- var cmd = _j.value;
547
- var opts = this._commandOptions(cmd);
548
- if (opts.length) {
549
- commandOpts.push(this.color(subtitleColors, "".concat(cmd.name, ":")));
550
- commandOpts.push("");
551
- try {
552
- for (var _k = (e_11 = void 0, __values(this._getWrappedLines(opts.map(function (c) { return ({
553
- name: _this._fullOptName(c),
554
- description: _this._optionDescription(c),
555
- additionalColorCount: c.defaultValue !== undefined ? 1 : 0,
556
- }); })))), _l = _k.next(); !_l.done; _l = _k.next()) {
557
- var line = _l.value;
558
- commandOpts.push(line);
559
- }
560
- }
561
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
562
- finally {
563
- try {
564
- if (_l && !_l.done && (_b = _k.return)) _b.call(_k);
565
- }
566
- finally { if (e_11) throw e_11.error; }
567
- }
568
- }
569
- }
570
- }
571
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
572
- finally {
573
- try {
574
- if (_j && !_j.done && (_a = _h.return)) _a.call(_h);
575
- }
576
- finally { if (e_10) throw e_10.error; }
577
- }
578
- lines.push(this.color(titleColors, commandOpts.length ? "Command Options:" : "Options:"));
579
- lines.push("");
580
- try {
581
- for (var commandOpts_1 = __values(commandOpts), commandOpts_1_1 = commandOpts_1.next(); !commandOpts_1_1.done; commandOpts_1_1 = commandOpts_1.next()) {
582
- var line = commandOpts_1_1.value;
583
- lines.push(line);
584
- }
585
- }
586
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
587
- finally {
588
- try {
589
- if (commandOpts_1_1 && !commandOpts_1_1.done && (_e = commandOpts_1.return)) _e.call(commandOpts_1);
590
- }
591
- finally { if (e_12) throw e_12.error; }
592
- }
593
- var globalOpts = this._globalOptions();
594
- if (globalOpts.length) {
595
- if (commandOpts.length) {
596
- lines.push(this.color(titleColors, "Global Options:"));
597
- lines.push("");
598
- }
599
- try {
600
- for (var _m = __values(this._getWrappedLines(globalOpts.map(function (c) { return ({ name: _this._fullOptName(c), description: _this._optionDescription(c) }); }))), _o = _m.next(); !_o.done; _o = _m.next()) {
601
- var line = _o.value;
602
- lines.push(line);
603
- }
604
- }
605
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
606
- finally {
607
- try {
608
- if (_o && !_o.done && (_f = _m.return)) _f.call(_m);
609
- }
610
- finally { if (e_13) throw e_13.error; }
611
- }
612
- }
613
- return lines;
614
- };
615
- Massarg.prototype._optionDescription = function (c) {
616
- if (c.defaultValue === undefined || !this._help.includeDefaults) {
617
- return c.description;
618
- }
619
- return [c.description, this.color(this._help.bodyColors, "(default: ".concat(c.defaultValue.toString().trim(), ")"))]
620
- .filter(Boolean)
621
- .join(" ");
622
- };
623
- Massarg.prototype._fullCmdName = function (cmd) {
624
- var _a;
625
- return __spreadArray([cmd.name], __read(((_a = cmd.aliases) !== null && _a !== void 0 ? _a : [])), false).join(this._help.commandNameSeparator);
626
- };
627
- Massarg.prototype._fullOptName = function (opt) {
628
- var _a;
629
- return __spreadArray(["--".concat(opt.name)], __read(((_a = opt.aliases) !== null && _a !== void 0 ? _a : []).map(function (a) { return "-".concat(a); })), false).join(this._help.optionNameSeparator);
630
- };
631
- Massarg.prototype._commandOptions = function (cmd) {
632
- return this._options.filter(function (o) {
633
- var _a;
634
- return ((0, utils_1.asArray)(o.commands).length && (0, utils_1.asArray)(o.commands).includes(cmd.name)) ||
635
- ((_a = cmd.aliases) === null || _a === void 0 ? void 0 : _a.some(function (a) { return (0, utils_1.asArray)(o.commands).includes(a); }));
636
- });
637
- };
638
- Massarg.prototype._optionCommands = function (opt) {
639
- return this._commands.filter(function (c) {
640
- return (0, utils_1.asArray)(opt.commands).some(function (_c) {
641
- var _a;
642
- return __spreadArray([c.name], __read(((_a = c.aliases) !== null && _a !== void 0 ? _a : [])), false).includes(_c);
643
- });
644
- });
645
- };
646
- Massarg.prototype._globalOptions = function () {
647
- return this._options.filter(function (o) { return !o.commands; });
648
- };
649
- Massarg.prototype.color = function (color) {
650
- var e_14, _a;
651
- var text = [];
652
- for (var _i = 1; _i < arguments.length; _i++) {
653
- text[_i - 1] = arguments[_i];
654
- }
655
- if (!this._help.useColors) {
656
- return text.join(" ");
657
- }
658
- var output = undefined;
659
- try {
660
- for (var _b = __values((0, utils_1.asArray)(color)), _e = _b.next(); !_e.done; _e = _b.next()) {
661
- var c = _e.value;
662
- output = chalk_1.default[c].apply(chalk_1.default, __spreadArray([], __read((output ? [output] : text)), false));
663
- }
664
- }
665
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
666
- finally {
667
- try {
668
- if (_e && !_e.done && (_a = _b.return)) _a.call(_b);
669
- }
670
- finally { if (e_14) throw e_14.error; }
671
- }
672
- return chalk_1.default.reset(output);
673
- };
674
- Massarg.prototype.colorCount = function () {
675
- var colors = [];
676
- for (var _i = 0; _i < arguments.length; _i++) {
677
- colors[_i] = arguments[_i];
678
- }
679
- if (!this._help.useColors) {
680
- return 0;
681
- }
682
- return utils_1.colorCount.apply(void 0, __spreadArray([], __read(colors), false));
683
- };
684
- return Massarg;
685
- }());
686
- exports.Massarg = Massarg;
687
- function massarg() {
688
- return new Massarg();
689
- }
690
- exports.massarg = massarg;
691
- exports.default = massarg;
692
- var templateObject_1;
17
+ __exportStar(require("./massarg"), exports);
693
18
  //# sourceMappingURL=index.js.map