@alcyone-labs/arg-parser 1.0.0
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/LICENSE +21 -0
- package/README.md +584 -0
- package/dist/ArgParser.d.ts +118 -0
- package/dist/ArgParser.d.ts.map +1 -0
- package/dist/FlagManager.d.ts +16 -0
- package/dist/FlagManager.d.ts.map +1 -0
- package/dist/index.cjs +1192 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.min.mjs +819 -0
- package/dist/index.min.mjs.map +1 -0
- package/dist/index.mjs +1192 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
var ae = (g) => {
|
|
2
|
+
throw TypeError(g);
|
|
3
|
+
};
|
|
4
|
+
var Q = (g, e, n) => e.has(g) || ae("Cannot " + n);
|
|
5
|
+
var t = (g, e, n) => (Q(g, e, "read from private field"), n ? n.call(g) : e.get(g)), N = (g, e, n) => e.has(g) ? ae("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(g) : e.set(g, n), M = (g, e, n, a) => (Q(g, e, "write to private field"), a ? a.call(g, n) : e.set(g, n), n), A = (g, e, n) => (Q(g, e, "access private method"), n);
|
|
6
|
+
import $ from "chalk";
|
|
7
|
+
import { createRegExp as de, anyOf as ue, oneOrMore as me, char as fe } from "magic-regexp";
|
|
8
|
+
import { z as f } from "zod";
|
|
9
|
+
const U = {}, he = f.object({
|
|
10
|
+
name: f.string().min(1, "Flag name cannot be empty").describe(
|
|
11
|
+
"The output property name, used as a return key `{name: value}`. Must be unique."
|
|
12
|
+
),
|
|
13
|
+
allowLigature: f.boolean().default(!0).describe(
|
|
14
|
+
"Enable both forms of flag input, e.g., `./script.js -f=value` and `-f value`."
|
|
15
|
+
),
|
|
16
|
+
allowMultiple: f.boolean().default(!1).describe(
|
|
17
|
+
"Allow passing the same flag multiple times, e.g., `-f val1 -f val2` results in an array."
|
|
18
|
+
),
|
|
19
|
+
description: f.union([f.string(), f.array(f.string())]).describe("Textual description for help messages."),
|
|
20
|
+
options: f.array(f.string().min(1)).min(1, "Flag must have at least one option (e.g., ['-f', '--flag'])").describe("Array of option strings, e.g., ['-f', '--flag']."),
|
|
21
|
+
defaultValue: f.any().optional().describe("Default value if the flag is not provided."),
|
|
22
|
+
type: f.union([
|
|
23
|
+
f.any().refine((g) => g === String, {
|
|
24
|
+
message: "Must be String constructor"
|
|
25
|
+
}),
|
|
26
|
+
f.any().refine((g) => g === Number, {
|
|
27
|
+
message: "Must be Number constructor"
|
|
28
|
+
}),
|
|
29
|
+
f.any().refine((g) => g === Boolean, {
|
|
30
|
+
message: "Must be Boolean constructor"
|
|
31
|
+
}),
|
|
32
|
+
f.any().refine((g) => g === Array, {
|
|
33
|
+
message: "Must be Array constructor"
|
|
34
|
+
}),
|
|
35
|
+
f.any().refine((g) => g === Object, {
|
|
36
|
+
message: "Must be Object constructor"
|
|
37
|
+
}),
|
|
38
|
+
f.function().args(f.string()).returns(f.any()),
|
|
39
|
+
// Custom parser function
|
|
40
|
+
f.string().refine(
|
|
41
|
+
(g) => ["boolean", "string", "number", "array", "object"].includes(
|
|
42
|
+
g.toLowerCase()
|
|
43
|
+
),
|
|
44
|
+
{
|
|
45
|
+
message: "Invalid type string. Must be one of 'boolean', 'string', 'number', 'array', 'object'."
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
]).default("string").describe(
|
|
49
|
+
"Expected data type or a custom parser function. Defaults to 'string'."
|
|
50
|
+
),
|
|
51
|
+
mandatory: f.union([f.boolean(), f.function().args(f.any()).returns(f.boolean())]).optional().describe(
|
|
52
|
+
"Makes the flag mandatory, can be a boolean or a function conditional on other args."
|
|
53
|
+
),
|
|
54
|
+
flagOnly: f.boolean().default(!1).describe(
|
|
55
|
+
"If true, the flag's presence is noted (true/false), and any subsequent value is not consumed by this flag."
|
|
56
|
+
),
|
|
57
|
+
validate: f.function().args(f.any().optional(), f.any().optional()).returns(
|
|
58
|
+
f.union([
|
|
59
|
+
f.boolean(),
|
|
60
|
+
f.string(),
|
|
61
|
+
f.void(),
|
|
62
|
+
f.promise(f.union([f.boolean(), f.string(), f.void()]))
|
|
63
|
+
])
|
|
64
|
+
).optional().describe(
|
|
65
|
+
"Custom validation function for the flag's value (receives value, parsedArgs)."
|
|
66
|
+
),
|
|
67
|
+
enum: f.array(f.any()).optional().describe("Array of allowed values for the flag.")
|
|
68
|
+
}).passthrough().transform((g) => {
|
|
69
|
+
const e = { ...g };
|
|
70
|
+
return "default" in e && e.default !== void 0 && !("defaultValue" in e) && (e.defaultValue = e.default), "required" in e && e.required !== void 0 && !("mandatory" in e) && (e.mandatory = e.required), e;
|
|
71
|
+
});
|
|
72
|
+
var L, Z;
|
|
73
|
+
const oe = class oe {
|
|
74
|
+
constructor(e = {}, n = []) {
|
|
75
|
+
N(this, L, /* @__PURE__ */ new Map());
|
|
76
|
+
N(this, Z);
|
|
77
|
+
M(this, Z, e.throwForDuplicateFlags ?? !1), this.addFlags(n);
|
|
78
|
+
}
|
|
79
|
+
static _safeFlag(e) {
|
|
80
|
+
const n = he.parse(e);
|
|
81
|
+
let a;
|
|
82
|
+
const l = n.type;
|
|
83
|
+
if (typeof l == "string")
|
|
84
|
+
switch (l.toLowerCase()) {
|
|
85
|
+
case "boolean":
|
|
86
|
+
a = Boolean;
|
|
87
|
+
break;
|
|
88
|
+
case "string":
|
|
89
|
+
a = String;
|
|
90
|
+
break;
|
|
91
|
+
case "number":
|
|
92
|
+
a = Number;
|
|
93
|
+
break;
|
|
94
|
+
case "array":
|
|
95
|
+
a = Array;
|
|
96
|
+
break;
|
|
97
|
+
case "object":
|
|
98
|
+
a = Object;
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`Invalid type string: ${l}`);
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
a = l;
|
|
105
|
+
return {
|
|
106
|
+
...n,
|
|
107
|
+
options: n.options,
|
|
108
|
+
type: a,
|
|
109
|
+
validate: n.validate,
|
|
110
|
+
enum: n.enum,
|
|
111
|
+
mandatory: n.mandatory
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
addFlag(e) {
|
|
115
|
+
const n = oe._safeFlag(e);
|
|
116
|
+
if (t(this, L).has(n.name)) {
|
|
117
|
+
if (t(this, Z))
|
|
118
|
+
throw new Error(
|
|
119
|
+
`FlagManager: Flag '${n.name}' already exists.`
|
|
120
|
+
);
|
|
121
|
+
return console.warn(
|
|
122
|
+
`Warning: FlagManager: Flag '${n.name}' already exists. Duplicate not added.`
|
|
123
|
+
), this;
|
|
124
|
+
}
|
|
125
|
+
return t(this, L).set(n.name, n), this;
|
|
126
|
+
}
|
|
127
|
+
_setProcessedFlagForInheritance(e) {
|
|
128
|
+
return t(this, L).has(e.name) ? this : (t(this, L).set(e.name, e), this);
|
|
129
|
+
}
|
|
130
|
+
addFlags(e) {
|
|
131
|
+
for (const n of e)
|
|
132
|
+
this.addFlag(n);
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
hasFlag(e) {
|
|
136
|
+
return t(this, L).has(e);
|
|
137
|
+
}
|
|
138
|
+
getFlag(e) {
|
|
139
|
+
return t(this, L).get(e);
|
|
140
|
+
}
|
|
141
|
+
get flags() {
|
|
142
|
+
return Array.from(t(this, L).values());
|
|
143
|
+
}
|
|
144
|
+
get flagNames() {
|
|
145
|
+
return Array.from(t(this, L).values()).map((e) => e.name);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
L = new WeakMap(), Z = new WeakMap();
|
|
149
|
+
let X = oe;
|
|
150
|
+
class R extends Error {
|
|
151
|
+
constructor(e, n = []) {
|
|
152
|
+
super(e), this.cmdChain = n, this.name = "ArgParserError", this.commandChain = n;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
var S, k, P, E, D, H, I, T, _, K, B, F, w, y, z, re, ie, Y, le, G, ce, ee, ne, te;
|
|
156
|
+
const W = class W {
|
|
157
|
+
constructor(e = {}, n) {
|
|
158
|
+
N(this, y);
|
|
159
|
+
N(this, S, "Argument Parser");
|
|
160
|
+
N(this, k);
|
|
161
|
+
N(this, P, "");
|
|
162
|
+
N(this, E, {
|
|
163
|
+
extraNewLine: !0,
|
|
164
|
+
wrapAtWidth: 50,
|
|
165
|
+
blankSpaceWidth: 30,
|
|
166
|
+
mandatoryCharacter: "*"
|
|
167
|
+
});
|
|
168
|
+
N(this, D);
|
|
169
|
+
N(this, H, !1);
|
|
170
|
+
N(this, I);
|
|
171
|
+
N(this, T, !0);
|
|
172
|
+
N(this, _);
|
|
173
|
+
N(this, K, {});
|
|
174
|
+
N(this, B, !1);
|
|
175
|
+
N(this, F, /* @__PURE__ */ new Map());
|
|
176
|
+
N(this, w);
|
|
177
|
+
M(this, S, e.appName || "app"), e.blankSpaceWidth && !isNaN(Number(e.blankSpaceWidth)) && Number(e.blankSpaceWidth) > 20 && (t(this, E).blankSpaceWidth = Number(e.blankSpaceWidth)), e.wrapAtWidth && !isNaN(Number(e.wrapAtWidth)) && Number(e.wrapAtWidth) > 30 && (t(this, E).wrapAtWidth = Number(e.wrapAtWidth)), typeof e.extraNewLine == "boolean" && (t(this, E).extraNewLine = !!e.extraNewLine), typeof e.mandatoryCharacter == "string" && (t(this, E).mandatoryCharacter = e.mandatoryCharacter), typeof e.throwForDuplicateFlags == "boolean" && M(this, H, e.throwForDuplicateFlags), M(this, w, new X(
|
|
178
|
+
{
|
|
179
|
+
throwForDuplicateFlags: t(this, H)
|
|
180
|
+
},
|
|
181
|
+
n || []
|
|
182
|
+
)), M(this, T, e.handleErrors ?? !0), M(this, B, e.inheritParentFlags ?? !1), M(this, I, e.description), M(this, D, e.handler), M(this, k, e.appCommandName);
|
|
183
|
+
const a = {
|
|
184
|
+
name: "help",
|
|
185
|
+
description: "Display this help message and exits",
|
|
186
|
+
mandatory: !1,
|
|
187
|
+
type: Boolean,
|
|
188
|
+
options: ["-h", "--help"],
|
|
189
|
+
defaultValue: void 0,
|
|
190
|
+
allowLigature: !1,
|
|
191
|
+
allowMultiple: !1,
|
|
192
|
+
flagOnly: !0,
|
|
193
|
+
enum: [],
|
|
194
|
+
validate: (l, i) => !0
|
|
195
|
+
// Ensure signature matches Zod schema for .args()
|
|
196
|
+
};
|
|
197
|
+
if (t(this, w).addFlag(a), e.subCommands)
|
|
198
|
+
for (const l of e.subCommands)
|
|
199
|
+
this.addSubCommand(l);
|
|
200
|
+
}
|
|
201
|
+
get flags() {
|
|
202
|
+
return t(this, w).flags;
|
|
203
|
+
}
|
|
204
|
+
get flagNames() {
|
|
205
|
+
return t(this, w).flagNames;
|
|
206
|
+
}
|
|
207
|
+
_addToOutput(e, n, a, l) {
|
|
208
|
+
let i = n;
|
|
209
|
+
if (e.type === Boolean ? typeof n == "boolean" ? i = n : typeof n == "string" ? i = /(true|yes|1)/i.test(n) : i = new e.type(i) : typeof e.type == "function" ? i = e.type(i) : typeof e.type == "object" && (i = new e.type(i)), e.enum && e.enum.length > 0) {
|
|
210
|
+
const o = e.enum.map((c) => typeof c == "string" ? `'${c}'` : c).join(", ");
|
|
211
|
+
if (!e.enum.includes(i))
|
|
212
|
+
throw new R(
|
|
213
|
+
`Invalid value '${i}' for flag '${$.yellow(e.name)}'. Allowed values: ${o}`,
|
|
214
|
+
this.getCommandChain()
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
if (e.validate) {
|
|
218
|
+
const o = e.validate(i, a);
|
|
219
|
+
if (o === !1)
|
|
220
|
+
throw new R(
|
|
221
|
+
`Validation failed for flag '${$.yellow(e.name)}' with value '${i}'`,
|
|
222
|
+
this.getCommandChain()
|
|
223
|
+
);
|
|
224
|
+
if (typeof o == "string")
|
|
225
|
+
throw new R(o, this.getCommandChain());
|
|
226
|
+
}
|
|
227
|
+
return e.allowMultiple && !Array.isArray(a[e.name]) && (a[e.name] = []), e.allowMultiple ? a[e.name].push(i) : a[e.name] = i;
|
|
228
|
+
}
|
|
229
|
+
addFlags(e) {
|
|
230
|
+
return t(this, w).addFlags(e), this;
|
|
231
|
+
}
|
|
232
|
+
addFlag(e) {
|
|
233
|
+
return t(this, w).addFlag(e), this;
|
|
234
|
+
}
|
|
235
|
+
addSubCommand(e) {
|
|
236
|
+
if (t(this, F).has(e.name))
|
|
237
|
+
throw new Error(`Sub-command '${e.name}' already exists`);
|
|
238
|
+
const n = e.parser;
|
|
239
|
+
if (!(n instanceof W))
|
|
240
|
+
throw new Error(
|
|
241
|
+
`Parser for subcommand '${e.name}' is not an instance of ArgParser. Please provide 'new ArgParser(...)' for the 'parser' property of an ISubCommand.`
|
|
242
|
+
);
|
|
243
|
+
if (M(n, _, this), M(n, P, e.name), !t(n, k) && t(this, k) && M(n, k, t(this, k)), t(n, B)) {
|
|
244
|
+
const a = t(this, w).flags;
|
|
245
|
+
for (const l of a)
|
|
246
|
+
t(n, w).hasFlag(l.name) || t(n, w)._setProcessedFlagForInheritance(l);
|
|
247
|
+
}
|
|
248
|
+
return t(this, F).set(e.name, e), e.handler && n.setHandler(e.handler), this;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Sets the handler function for this specific parser instance.
|
|
252
|
+
* This handler will be executed if this parser is the final one
|
|
253
|
+
* in the command chain and `executeHandlers` is enabled on the root parser.
|
|
254
|
+
*
|
|
255
|
+
* @param handler - The function to execute.
|
|
256
|
+
* @returns The ArgParser instance for chaining.
|
|
257
|
+
*/
|
|
258
|
+
setHandler(e) {
|
|
259
|
+
return M(this, D, e), this;
|
|
260
|
+
}
|
|
261
|
+
printAll(e) {
|
|
262
|
+
if (e)
|
|
263
|
+
try {
|
|
264
|
+
const n = U.dirname(e);
|
|
265
|
+
if (U.existsSync(n) || U.mkdirSync(n, { recursive: !0 }), e.toLowerCase().endsWith(".json")) {
|
|
266
|
+
const a = A(this, y, te).call(this, this), l = JSON.stringify(a, null, 2);
|
|
267
|
+
U.writeFileSync(e, l), console.log(`ArgParser configuration JSON dumped to: ${e}`);
|
|
268
|
+
} else {
|
|
269
|
+
const l = A(this, y, ne).call(this, this, 0).replace(
|
|
270
|
+
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
|
271
|
+
""
|
|
272
|
+
);
|
|
273
|
+
U.writeFileSync(e, l), console.log(`ArgParser configuration text dumped to: ${e}`);
|
|
274
|
+
}
|
|
275
|
+
} catch (n) {
|
|
276
|
+
console.error(
|
|
277
|
+
`Error writing ArgParser configuration to file '${e}':`,
|
|
278
|
+
n
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
else
|
|
282
|
+
console.log(`
|
|
283
|
+
--- ArgParser Configuration Dump ---`), A(this, y, ee).call(this, this, 0), console.log("--- End Configuration Dump ---\\n");
|
|
284
|
+
}
|
|
285
|
+
parse(e, n) {
|
|
286
|
+
if (A(this, y, re).call(this, e, n))
|
|
287
|
+
return {};
|
|
288
|
+
try {
|
|
289
|
+
const {
|
|
290
|
+
finalParser: a,
|
|
291
|
+
commandChain: l,
|
|
292
|
+
parserChain: i
|
|
293
|
+
} = A(this, y, z).call(this, e, this, [], [this]), { finalArgs: o, handlerToExecute: c } = this._parseRecursive(
|
|
294
|
+
e,
|
|
295
|
+
this,
|
|
296
|
+
{},
|
|
297
|
+
[],
|
|
298
|
+
n
|
|
299
|
+
);
|
|
300
|
+
return l.length > 0 && (o.$commandChain = l), A(this, y, ie).call(this, o, i, l), A(this, y, Y).call(this, o, a), A(this, y, le).call(this, c, o, (n == null ? void 0 : n.skipHandlers) ?? !1), o;
|
|
301
|
+
} catch (a) {
|
|
302
|
+
if (a instanceof R) {
|
|
303
|
+
if (t(this, T))
|
|
304
|
+
return A(this, y, ce).call(this, a), {};
|
|
305
|
+
throw a;
|
|
306
|
+
} else
|
|
307
|
+
throw a;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Recursive helper for parsing arguments and handling sub-commands.
|
|
312
|
+
* This method assumes the global help check has already been performed in `parse`.
|
|
313
|
+
*/
|
|
314
|
+
_parseRecursive(e, n, a, l, i) {
|
|
315
|
+
var j, p;
|
|
316
|
+
let o = -1, c = null;
|
|
317
|
+
for (let b = 0; b < e.length; b++) {
|
|
318
|
+
const O = e[b];
|
|
319
|
+
if (t(n, F).has(O)) {
|
|
320
|
+
o = b, c = O;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const s = o === -1 ? e : e.slice(0, o), { parsedArgs: r, firstUnconsumedIndex: m } = A(j = n, y, G).call(j, s, i);
|
|
325
|
+
A(p = n, y, Y).call(p, r, n);
|
|
326
|
+
const u = {
|
|
327
|
+
...a,
|
|
328
|
+
...r
|
|
329
|
+
};
|
|
330
|
+
if (o === -1 || c === null) {
|
|
331
|
+
if (m < s.length) {
|
|
332
|
+
const x = s[m];
|
|
333
|
+
throw new R(
|
|
334
|
+
`Unknown command: '${$.yellow(x)}'`,
|
|
335
|
+
l
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
const b = { ...u };
|
|
339
|
+
l.length > 0 && (b.$commandChain = l);
|
|
340
|
+
let O;
|
|
341
|
+
return t(n, D) && (O = {
|
|
342
|
+
handler: t(n, D),
|
|
343
|
+
context: {
|
|
344
|
+
args: r,
|
|
345
|
+
parentArgs: a,
|
|
346
|
+
commandChain: l,
|
|
347
|
+
parser: n
|
|
348
|
+
}
|
|
349
|
+
}), { finalArgs: b, handlerToExecute: O };
|
|
350
|
+
}
|
|
351
|
+
if (m < s.length) {
|
|
352
|
+
const b = s[m];
|
|
353
|
+
throw new R(
|
|
354
|
+
`Unknown command: '${$.yellow(b)}'`,
|
|
355
|
+
l
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
const d = t(n, F).get(c);
|
|
359
|
+
if (!d || !(d.parser instanceof W))
|
|
360
|
+
throw new R(
|
|
361
|
+
`Internal error: Subcommand '${c}' is misconfigured or its parser is not a valid ArgParser instance.`,
|
|
362
|
+
l
|
|
363
|
+
);
|
|
364
|
+
const h = d.parser, C = e.slice(o + 1), v = [...l, c], V = {
|
|
365
|
+
...a,
|
|
366
|
+
...r
|
|
367
|
+
};
|
|
368
|
+
return this._parseRecursive(
|
|
369
|
+
C,
|
|
370
|
+
h,
|
|
371
|
+
V,
|
|
372
|
+
v,
|
|
373
|
+
i
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
helpText() {
|
|
377
|
+
const e = $.cyan, n = $.green, a = $.white, l = $.red, i = $.dim;
|
|
378
|
+
let o = t(this, S), c = this;
|
|
379
|
+
for (; t(c, _); )
|
|
380
|
+
c = t(c, _);
|
|
381
|
+
c && (o = t(c, S));
|
|
382
|
+
const s = t(this, P) ? `${o} ${t(this, P)}` : o;
|
|
383
|
+
let r = `${e(`${s} Help`)} (${t(this, E).mandatoryCharacter} = Mandatory fields):
|
|
384
|
+
|
|
385
|
+
`;
|
|
386
|
+
t(this, I) && (r += `${a(t(this, I))}
|
|
387
|
+
|
|
388
|
+
`);
|
|
389
|
+
const m = (d = 1) => " ".repeat(d);
|
|
390
|
+
t(this, F).size > 0 && (r += `${e("Available sub-commands:")}
|
|
391
|
+
`, r += Array.from(t(this, F).entries()).sort(([d], [h]) => d.localeCompare(h)).map(([d, h]) => {
|
|
392
|
+
const C = h.parser;
|
|
393
|
+
if (!(C instanceof W))
|
|
394
|
+
return `${m()}${n(d.padEnd(20))} [Error: Subcommand '${d}' has an invalid parser configuration]`;
|
|
395
|
+
let v = `${m()}${n(d.padEnd(20))} ${a(t(C, I) || "")}`;
|
|
396
|
+
const j = ((C && t(C, w) ? t(C, w).flags : void 0) || []).filter(
|
|
397
|
+
(b) => b.name !== "help"
|
|
398
|
+
);
|
|
399
|
+
j.length > 0 ? (v += `
|
|
400
|
+
${m(2)}${i("Flags:")}`, j.sort(
|
|
401
|
+
(b, O) => b.name.localeCompare(O.name)
|
|
402
|
+
).forEach((b) => {
|
|
403
|
+
const O = b.options.map((J) => n(J)).join(", "), x = Array.isArray(b.description) ? b.description[0] : b.description;
|
|
404
|
+
v += `
|
|
405
|
+
${m(3)}${O} - ${i(x)}`;
|
|
406
|
+
})) : v += `
|
|
407
|
+
${m(2)}${i("Flags:")} none`;
|
|
408
|
+
const p = Array.from(
|
|
409
|
+
t(C, F).keys()
|
|
410
|
+
);
|
|
411
|
+
return p.length > 0 ? v += `
|
|
412
|
+
${m(2)}${i("Sub-commands:")} ${p.join(", ")}` : v += `
|
|
413
|
+
${m(2)}${i("Sub-commands:")} none`, v;
|
|
414
|
+
}).join(`
|
|
415
|
+
|
|
416
|
+
`), r += `
|
|
417
|
+
`), r += `
|
|
418
|
+
${e("Flags:")}
|
|
419
|
+
`;
|
|
420
|
+
const u = t(this, w).flags;
|
|
421
|
+
return u.length > 0 ? r += u.sort((d, h) => d.name.localeCompare(h.name)).map((d) => {
|
|
422
|
+
const h = d.options.toSorted((x, J) => x.length - J.length).map((x) => n(x)).join(", "), C = typeof d.mandatory == "function" ? "dynamic" : d.mandatory, v = C === !0 ? ` ${l(t(this, E).mandatoryCharacter)}` : C === "dynamic" ? ` ${i("(conditionally mandatory)")}` : "", V = Array.isArray(d.description) ? d.description : [d.description], j = [];
|
|
423
|
+
let p = "unknown";
|
|
424
|
+
typeof d.type == "function" ? (p = d.type.name || "custom function", p === "Boolean" && (p = "boolean"), p === "String" && (p = "string"), p === "Number" && (p = "number"), p === "Array" && (p = "array"), p === "Object" && (p = "object")) : typeof d.type == "string" && (p = d.type), j.push(`Type: ${p}`), d.flagOnly && j.push("Flag only (no value expected)"), d.defaultValue !== void 0 && d.defaultValue !== null && j.push(`Default: ${JSON.stringify(d.defaultValue)}`), d.enum && d.enum.length > 0 && j.push(
|
|
425
|
+
`Allowed values: ${d.enum.map((x) => `'${x}'`).join(", ")}`
|
|
426
|
+
);
|
|
427
|
+
const b = Math.max(
|
|
428
|
+
...u.map(
|
|
429
|
+
(x) => x.options.join(", ").length
|
|
430
|
+
),
|
|
431
|
+
0
|
|
432
|
+
), O = h.padEnd(b + 5) + v;
|
|
433
|
+
return `
|
|
434
|
+
${m()}${O}
|
|
435
|
+
${m(2)}${a(V[0])}
|
|
436
|
+
${j.map((x) => `${m(3)}${i(x)}`).join(`
|
|
437
|
+
`)}
|
|
438
|
+
${V.slice(1).map((x) => `
|
|
439
|
+
${m(2)}${a(x)}`).join("")}
|
|
440
|
+
`.trim();
|
|
441
|
+
}).join(`
|
|
442
|
+
|
|
443
|
+
`) : r += `${m()}${i("none")}`, r;
|
|
444
|
+
}
|
|
445
|
+
getSubCommand(e) {
|
|
446
|
+
return t(this, F).get(e);
|
|
447
|
+
}
|
|
448
|
+
hasFlag(e) {
|
|
449
|
+
return t(this, w).hasFlag(e);
|
|
450
|
+
}
|
|
451
|
+
getCommandChain() {
|
|
452
|
+
const e = [];
|
|
453
|
+
let n = this;
|
|
454
|
+
for (; n && t(n, _); )
|
|
455
|
+
e.unshift(t(n, P)), n = t(n, _);
|
|
456
|
+
return e;
|
|
457
|
+
}
|
|
458
|
+
getLastParseResult() {
|
|
459
|
+
return t(this, K);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
S = new WeakMap(), k = new WeakMap(), P = new WeakMap(), E = new WeakMap(), D = new WeakMap(), H = new WeakMap(), I = new WeakMap(), T = new WeakMap(), _ = new WeakMap(), K = new WeakMap(), B = new WeakMap(), F = new WeakMap(), w = new WeakMap(), y = new WeakSet(), z = function(e, n, a, l) {
|
|
463
|
+
let i = -1, o = null;
|
|
464
|
+
for (let d = 0; d < e.length; d++) {
|
|
465
|
+
const h = e[d];
|
|
466
|
+
if (t(n, F).has(h)) {
|
|
467
|
+
i = d, o = h;
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (i === -1 || o === null)
|
|
472
|
+
return {
|
|
473
|
+
finalParser: n,
|
|
474
|
+
commandChain: a,
|
|
475
|
+
parserChain: l,
|
|
476
|
+
remainingArgs: e
|
|
477
|
+
};
|
|
478
|
+
const c = t(n, F).get(o);
|
|
479
|
+
if (!c || !(c.parser instanceof W))
|
|
480
|
+
throw new Error(
|
|
481
|
+
`Internal error: Subcommand '${o}' configuration is invalid or parser is missing.`
|
|
482
|
+
);
|
|
483
|
+
const s = c.parser, r = e.slice(i + 1), m = [...a, o], u = [...l, s];
|
|
484
|
+
return A(this, y, z).call(this, r, s, m, u);
|
|
485
|
+
}, re = function(e, n) {
|
|
486
|
+
var o, c, s, r;
|
|
487
|
+
if (e.length === 0 && !t(this, _) && !t(this, D))
|
|
488
|
+
return console.log(this.helpText()), typeof process == "object" && typeof process.exit == "function" && process.exit(0), !0;
|
|
489
|
+
if (e.includes("--LIB-debug-print"))
|
|
490
|
+
return this.printAll("ArgParser.full.json"), typeof process == "object" && typeof process.exit == "function" && process.exit(0), !0;
|
|
491
|
+
const { finalParser: a } = A(this, y, z).call(this, e, this, [], [this]);
|
|
492
|
+
if (e.includes("--LIB-debug")) {
|
|
493
|
+
console.log(
|
|
494
|
+
$.yellow.bold(`
|
|
495
|
+
--- ArgParser --LIB-debug Runtime Context ---`)
|
|
496
|
+
);
|
|
497
|
+
const {
|
|
498
|
+
commandChain: m,
|
|
499
|
+
parserChain: u
|
|
500
|
+
} = A(this, y, z).call(this, e, this, [], [this]);
|
|
501
|
+
console.log(
|
|
502
|
+
`Identified Command Chain: ${$.cyan(m.join(" -> ") || "(root)")}`
|
|
503
|
+
), console.log(
|
|
504
|
+
`Identified Final Parser: ${$.cyan(t(a, P) || t(a, S))}`
|
|
505
|
+
);
|
|
506
|
+
let d = this, h = [...e], C = {};
|
|
507
|
+
const v = [], V = h.findIndex(
|
|
508
|
+
(p) => t(d, F).has(p)
|
|
509
|
+
), j = V === -1 ? h : h.slice(0, V);
|
|
510
|
+
v.push({ level: "(root)", argsSlice: j });
|
|
511
|
+
try {
|
|
512
|
+
const { parsedArgs: p } = A(o = d, y, G).call(o, j, { skipHelpHandling: !0 });
|
|
513
|
+
v[0].parsed = p, C = { ...C, ...p };
|
|
514
|
+
} catch (p) {
|
|
515
|
+
v[0].error = p.message;
|
|
516
|
+
}
|
|
517
|
+
h = V === -1 ? [] : h.slice(V);
|
|
518
|
+
for (let p = 0; p < m.length; p++) {
|
|
519
|
+
const b = m[p];
|
|
520
|
+
if (!t(d, F).has(b)) {
|
|
521
|
+
v.push({
|
|
522
|
+
level: "Error",
|
|
523
|
+
argsSlice: [],
|
|
524
|
+
error: `Could not find sub-command parser for '${b}'`
|
|
525
|
+
});
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
d = (c = t(d, F).get(b)) == null ? void 0 : c.parser, h = h.slice(1);
|
|
529
|
+
const O = h.findIndex(
|
|
530
|
+
(q) => t(d, F).has(q)
|
|
531
|
+
), x = O === -1 ? h : h.slice(0, O), J = {
|
|
532
|
+
level: b,
|
|
533
|
+
argsSlice: x
|
|
534
|
+
};
|
|
535
|
+
v.push(J);
|
|
536
|
+
try {
|
|
537
|
+
const { parsedArgs: q } = A(s = d, y, G).call(s, x, {
|
|
538
|
+
skipHelpHandling: !0
|
|
539
|
+
});
|
|
540
|
+
J.parsed = q, C = { ...C, ...q };
|
|
541
|
+
} catch (q) {
|
|
542
|
+
J.error = q.message;
|
|
543
|
+
}
|
|
544
|
+
h = O === -1 ? [] : h.slice(O);
|
|
545
|
+
}
|
|
546
|
+
return console.log($.yellow(`
|
|
547
|
+
Parsing Simulation Steps:`)), v.forEach((p) => {
|
|
548
|
+
console.log(` Level: ${$.cyan(p.level)}`), console.log(
|
|
549
|
+
` Args Slice Considered: ${JSON.stringify(p.argsSlice)}`
|
|
550
|
+
), p.parsed && console.log(
|
|
551
|
+
` Parsed Args at this Level: ${JSON.stringify(p.parsed)}`
|
|
552
|
+
), p.error && console.log(
|
|
553
|
+
` ${$.red("Error during parse simulation:")} ${p.error}`
|
|
554
|
+
);
|
|
555
|
+
}), console.log(
|
|
556
|
+
$.yellow(
|
|
557
|
+
`
|
|
558
|
+
Final Accumulated Args State (before final validation):`
|
|
559
|
+
)
|
|
560
|
+
), console.log(JSON.stringify(C, null, 2)), console.log($.yellow(`
|
|
561
|
+
Arguments Remaining After Simulation:`)), console.log(JSON.stringify(h, null, 2)), console.log(
|
|
562
|
+
$.yellow.bold(
|
|
563
|
+
`
|
|
564
|
+
--- ArgParser Static Configuration (Final Parser) ---`
|
|
565
|
+
)
|
|
566
|
+
), a.printAll(), console.log($.yellow.bold("--- End ArgParser --LIB-debug ---")), typeof process == "object" && typeof process.exit == "function" && process.exit(0), !0;
|
|
567
|
+
}
|
|
568
|
+
let l = "undefined_parser";
|
|
569
|
+
if (a instanceof W ? l = a["#subCommandName"] || a["#appName"] : a && (l = a.name || a.appName || "unknown_type"), !(a instanceof W))
|
|
570
|
+
return console.error(
|
|
571
|
+
`[ArgParser #_handleGlobalChecks Critical Error] identifiedFinalParser is not an instance of ArgParser. Cannot process help. Name: ${l}, Constructor: ${a ? (r = a.constructor) == null ? void 0 : r.name : "undefined"}`
|
|
572
|
+
), !1;
|
|
573
|
+
const i = t(a, w).getFlag("help");
|
|
574
|
+
if (i && !(n != null && n.skipHelpHandling)) {
|
|
575
|
+
const m = i.options;
|
|
576
|
+
if (e.some(
|
|
577
|
+
(d) => m.includes(d)
|
|
578
|
+
))
|
|
579
|
+
return console.log(a.helpText()), typeof process == "object" && typeof process.exit == "function" && process.exit(0), !0;
|
|
580
|
+
}
|
|
581
|
+
return !1;
|
|
582
|
+
}, ie = function(e, n, a) {
|
|
583
|
+
const l = [], i = /* @__PURE__ */ new Set();
|
|
584
|
+
for (const o of n) {
|
|
585
|
+
const c = o.getCommandChain();
|
|
586
|
+
for (const s of t(o, w).flags) {
|
|
587
|
+
if (s.name === "help" || i.has(s.name) || !(typeof s.mandatory == "function" ? s.mandatory(e) : s.mandatory)) continue;
|
|
588
|
+
const m = e[s.name];
|
|
589
|
+
let u = !1;
|
|
590
|
+
s.allowMultiple ? (m === void 0 || Array.isArray(m) && m.length === 0) && (u = !0) : m === void 0 && (u = !0), u && (i.has(s.name) || (l.push({
|
|
591
|
+
name: s.name,
|
|
592
|
+
parserName: t(o, P) || t(o, S),
|
|
593
|
+
commandChain: c
|
|
594
|
+
}), i.add(s.name)));
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (l.length > 0)
|
|
598
|
+
throw new R(
|
|
599
|
+
`Missing mandatory flags: ${l.map((o) => $.yellow(o.name)).join(", ")}`,
|
|
600
|
+
a
|
|
601
|
+
);
|
|
602
|
+
}, Y = function(e, n) {
|
|
603
|
+
for (const a of t(n, w).flags) {
|
|
604
|
+
const l = a.name;
|
|
605
|
+
e[l] === void 0 && a.defaultValue !== void 0 && (a.allowMultiple ? e[l] = Array.isArray(a.defaultValue) ? a.defaultValue : [a.defaultValue] : e[l] = a.defaultValue);
|
|
606
|
+
}
|
|
607
|
+
}, le = function(e, n, a) {
|
|
608
|
+
if (a || !e)
|
|
609
|
+
return;
|
|
610
|
+
const l = e.context.parser, i = t(l, w).flags, o = e.context.args;
|
|
611
|
+
for (const c of i) {
|
|
612
|
+
const s = c.name;
|
|
613
|
+
n.hasOwnProperty(s) ? o[s] = n[s] : c.allowMultiple && !o.hasOwnProperty(s) && (o[s] = []);
|
|
614
|
+
}
|
|
615
|
+
e.context.args = o, e.handler(e.context);
|
|
616
|
+
}, G = function(e, n) {
|
|
617
|
+
var c, s;
|
|
618
|
+
const a = t(this, w).flags, l = Object.fromEntries(
|
|
619
|
+
a.map((r) => [
|
|
620
|
+
r.name,
|
|
621
|
+
r.allowMultiple ? [] : void 0
|
|
622
|
+
])
|
|
623
|
+
);
|
|
624
|
+
let i = /* @__PURE__ */ new Set();
|
|
625
|
+
for (const r of a)
|
|
626
|
+
if (r.allowLigature && !r.flagOnly) {
|
|
627
|
+
const m = de(
|
|
628
|
+
ue(
|
|
629
|
+
...r.options.map((u) => `${u}=`)
|
|
630
|
+
),
|
|
631
|
+
me(fe).groupedAs("arg")
|
|
632
|
+
);
|
|
633
|
+
for (let u = 0; u < e.length; u++) {
|
|
634
|
+
if (i.has(u)) continue;
|
|
635
|
+
const d = e[u], h = m.exec(`${d}`);
|
|
636
|
+
if ((c = h == null ? void 0 : h.groups) != null && c.arg && (this._addToOutput(
|
|
637
|
+
r,
|
|
638
|
+
(s = h == null ? void 0 : h.groups) == null ? void 0 : s.arg,
|
|
639
|
+
l,
|
|
640
|
+
n
|
|
641
|
+
), i.add(u), !r.allowMultiple))
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
for (const r of a)
|
|
646
|
+
for (let m = 0; m < e.length; m++) {
|
|
647
|
+
if (i.has(m)) continue;
|
|
648
|
+
const u = e[m], d = m + 1, h = d < e.length, C = h ? e[d] : void 0, v = typeof C == "string" && C.startsWith("-");
|
|
649
|
+
if (r.options.includes(u) && (i.add(m), r.flagOnly ? this._addToOutput(r, !0, l, n) : h && !v ? (this._addToOutput(r, C, l, n), i.add(d)) : r.type === Boolean && this._addToOutput(r, !0, l, n), !r.allowMultiple))
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
let o = e.length;
|
|
653
|
+
for (let r = 0; r < e.length; r++)
|
|
654
|
+
if (!i.has(r)) {
|
|
655
|
+
o = r;
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
return { parsedArgs: l, firstUnconsumedIndex: o };
|
|
659
|
+
}, ce = function(e) {
|
|
660
|
+
let n = "your-script";
|
|
661
|
+
if (t(this, k))
|
|
662
|
+
n = t(this, k);
|
|
663
|
+
else if (t(this, S) && t(this, S) !== "Argument Parser")
|
|
664
|
+
n = t(this, S);
|
|
665
|
+
else if (typeof process < "u" && process.argv && process.argv[1])
|
|
666
|
+
try {
|
|
667
|
+
n = U.basename(process.argv[1]);
|
|
668
|
+
} catch {
|
|
669
|
+
}
|
|
670
|
+
const a = [
|
|
671
|
+
n,
|
|
672
|
+
...e.commandChain || []
|
|
673
|
+
].join(" ");
|
|
674
|
+
if (console.error(`
|
|
675
|
+
${$.red.bold("Error:")} ${e.message}`), console.error(
|
|
676
|
+
`
|
|
677
|
+
${$.dim(`Try '${a} --help' for usage details.`)}`
|
|
678
|
+
), typeof process == "object" && typeof process.exit == "function")
|
|
679
|
+
process.exit(1);
|
|
680
|
+
else
|
|
681
|
+
throw e;
|
|
682
|
+
}, ee = function(e, n, a = /* @__PURE__ */ new Set()) {
|
|
683
|
+
const l = " ".repeat(n), i = " ".repeat(n + 1), o = " ".repeat(n + 2);
|
|
684
|
+
console.log(
|
|
685
|
+
`${l}Parser: ${$.blueBright(t(e, P) || t(e, S))}`
|
|
686
|
+
), t(e, I) && console.log(`${i}Description: ${t(e, I)}`), console.log(`${i}Options:`), console.log(`${o}appName: ${t(e, S)}`), console.log(
|
|
687
|
+
`${o}appCommandName: ${t(e, k) ?? $.dim("undefined")}`
|
|
688
|
+
), console.log(`${o}handleErrors: ${t(e, T)}`), console.log(
|
|
689
|
+
`${o}throwForDuplicateFlags: ${t(e, H)}`
|
|
690
|
+
), console.log(
|
|
691
|
+
`${o}inheritParentFlags: ${t(e, B)}`
|
|
692
|
+
), console.log(`${o}Handler Defined: ${!!t(e, D)}`), console.log(
|
|
693
|
+
`${i}Internal Params: ${JSON.stringify(t(e, E))}`
|
|
694
|
+
);
|
|
695
|
+
const c = t(e, w).flags;
|
|
696
|
+
c.length > 0 ? (console.log(`${i}Flags (${c.length}):`), c.forEach((r) => {
|
|
697
|
+
console.log(`${o}* ${$.green(r.name)}:`), console.log(`${o} Options: ${r.options.join(", ")}`), console.log(
|
|
698
|
+
`${o} Description: ${Array.isArray(r.description) ? r.description.join(" | ") : r.description}`
|
|
699
|
+
), console.log(
|
|
700
|
+
`${o} Type: ${typeof r.type == "function" ? r.type.name || "custom function" : r.type}`
|
|
701
|
+
), console.log(
|
|
702
|
+
`${o} Mandatory: ${typeof r.mandatory == "function" ? "dynamic" : r.mandatory ?? !1}`
|
|
703
|
+
), console.log(
|
|
704
|
+
`${o} Default: ${JSON.stringify(r.defaultValue)}`
|
|
705
|
+
), console.log(`${o} Flag Only: ${r.flagOnly}`), console.log(`${o} Allow Multiple: ${r.allowMultiple}`), console.log(`${o} Allow Ligature: ${r.allowLigature}`), console.log(
|
|
706
|
+
`${o} Enum: ${r.enum && r.enum.length > 0 ? r.enum.join(", ") : "none"}`
|
|
707
|
+
), console.log(`${o} Validator Defined: ${!!r.validate}`);
|
|
708
|
+
})) : console.log(`${i}Flags: ${$.dim("none")}`);
|
|
709
|
+
const s = Array.from(t(e, F).values());
|
|
710
|
+
s.length > 0 ? (console.log(`${i}Sub-Commands (${s.length}):`), s.forEach((r) => {
|
|
711
|
+
A(this, y, ee).call(this, r.parser, n + 1, a);
|
|
712
|
+
})) : console.log(`${i}Sub-Commands: ${$.dim("none")}`);
|
|
713
|
+
}, ne = function(e, n, a = /* @__PURE__ */ new Set()) {
|
|
714
|
+
if (a.has(e)) return "";
|
|
715
|
+
a.add(e);
|
|
716
|
+
let l = "";
|
|
717
|
+
const i = " ".repeat(n), o = " ".repeat(n + 1), c = " ".repeat(n + 2), s = (u) => {
|
|
718
|
+
l += u + "\\n";
|
|
719
|
+
};
|
|
720
|
+
s(
|
|
721
|
+
`${i}Parser: ${t(e, P) || t(e, S)}`
|
|
722
|
+
// #appName is guaranteed
|
|
723
|
+
), t(e, I) && s(`${o}Description: ${t(e, I)}`), s(`${o}Options:`), s(`${c}appName: ${t(e, S)}`), s(
|
|
724
|
+
`${c}appCommandName: ${t(e, k) ?? "undefined"}`
|
|
725
|
+
), s(`${c}handleErrors: ${t(e, T)}`), s(
|
|
726
|
+
`${c}throwForDuplicateFlags: ${t(e, H)}`
|
|
727
|
+
), s(`${c}inheritParentFlags: ${t(e, B)}`), s(`${c}Handler Defined: ${!!t(e, D)}`), s(
|
|
728
|
+
`${o}Internal Params: ${JSON.stringify(t(e, E))}`
|
|
729
|
+
);
|
|
730
|
+
const r = t(e, w).flags;
|
|
731
|
+
r.length > 0 ? (s(`${o}Flags (${r.length}):`), r.forEach((u) => {
|
|
732
|
+
var h;
|
|
733
|
+
s(`${c}* ${u.name}:`), s(`${c} Options: ${u.options.join(", ")}`), s(
|
|
734
|
+
`${c} Description: ${Array.isArray(u.description) ? u.description.join(" | ") : u.description}`
|
|
735
|
+
);
|
|
736
|
+
let d = "unknown";
|
|
737
|
+
if (typeof u.type == "function")
|
|
738
|
+
d = u.type.name || "custom function";
|
|
739
|
+
else if (typeof u.type == "string")
|
|
740
|
+
d = u.type;
|
|
741
|
+
else if (typeof u.type == "object" && u.type)
|
|
742
|
+
try {
|
|
743
|
+
d = ((h = u.type.constructor) == null ? void 0 : h.name) || "object";
|
|
744
|
+
} catch {
|
|
745
|
+
d = "object";
|
|
746
|
+
}
|
|
747
|
+
s(`${c} Type: ${d}`), s(
|
|
748
|
+
`${c} Mandatory: ${typeof u.mandatory == "function" ? "dynamic" : u.mandatory ?? !1}`
|
|
749
|
+
), s(
|
|
750
|
+
`${c} Default: ${JSON.stringify(u.defaultValue)}`
|
|
751
|
+
), s(`${c} Flag Only: ${u.flagOnly}`), s(`${c} Allow Multiple: ${u.allowMultiple}`), s(`${c} Allow Ligature: ${u.allowLigature}`), s(
|
|
752
|
+
`${c} Enum: ${u.enum && u.enum.length > 0 ? u.enum.join(", ") : "none"}`
|
|
753
|
+
), s(`${c} Validator Defined: ${!!u.validate}`);
|
|
754
|
+
})) : s(`${o}Flags: none`);
|
|
755
|
+
const m = Array.from(t(e, F).values());
|
|
756
|
+
return m.length > 0 ? (s(`${o}Sub-Commands (${m.length}):`), m.forEach((u) => {
|
|
757
|
+
l += A(this, y, ne).call(this, u.parser, n + 1, a);
|
|
758
|
+
})) : s(`${o}Sub-Commands: none`), l;
|
|
759
|
+
}, te = function(e, n = /* @__PURE__ */ new Set()) {
|
|
760
|
+
if (n.has(e))
|
|
761
|
+
return {
|
|
762
|
+
note: `Reference to already processed parser: ${t(e, P) || t(e, S)}`
|
|
763
|
+
};
|
|
764
|
+
n.add(e);
|
|
765
|
+
const a = {
|
|
766
|
+
parserName: t(e, P) || t(e, S),
|
|
767
|
+
// #appName is guaranteed
|
|
768
|
+
description: t(e, I),
|
|
769
|
+
options: {
|
|
770
|
+
appName: t(e, S),
|
|
771
|
+
appCommandName: t(e, k) ?? void 0,
|
|
772
|
+
handleErrors: t(e, T),
|
|
773
|
+
throwForDuplicateFlags: t(e, H),
|
|
774
|
+
inheritParentFlags: t(e, B)
|
|
775
|
+
},
|
|
776
|
+
handlerDefined: !!t(e, D),
|
|
777
|
+
internalParams: t(e, E),
|
|
778
|
+
flags: [],
|
|
779
|
+
subCommands: {}
|
|
780
|
+
// Will be an object where keys are sub-command names
|
|
781
|
+
}, l = t(e, w).flags;
|
|
782
|
+
a.flags = l.map((o) => {
|
|
783
|
+
var s;
|
|
784
|
+
let c = "unknown";
|
|
785
|
+
if (typeof o.type == "function")
|
|
786
|
+
c = o.type.name || "custom function";
|
|
787
|
+
else if (typeof o.type == "string")
|
|
788
|
+
c = o.type;
|
|
789
|
+
else if (typeof o.type == "object" && o.type)
|
|
790
|
+
try {
|
|
791
|
+
c = ((s = o.type.constructor) == null ? void 0 : s.name) || "object";
|
|
792
|
+
} catch {
|
|
793
|
+
c = "object";
|
|
794
|
+
}
|
|
795
|
+
return {
|
|
796
|
+
name: o.name,
|
|
797
|
+
options: o.options,
|
|
798
|
+
description: o.description,
|
|
799
|
+
type: c,
|
|
800
|
+
mandatory: typeof o.mandatory == "function" ? "dynamic" : o.mandatory ?? !1,
|
|
801
|
+
defaultValue: o.defaultValue,
|
|
802
|
+
flagOnly: o.flagOnly,
|
|
803
|
+
allowMultiple: o.allowMultiple,
|
|
804
|
+
allowLigature: o.allowLigature,
|
|
805
|
+
enum: o.enum,
|
|
806
|
+
validatorDefined: !!o.validate
|
|
807
|
+
};
|
|
808
|
+
});
|
|
809
|
+
const i = Array.from(t(e, F).values());
|
|
810
|
+
return i.length > 0 && i.forEach((o) => {
|
|
811
|
+
a.subCommands[o.name] = A(this, y, te).call(this, o.parser, n);
|
|
812
|
+
}), a;
|
|
813
|
+
};
|
|
814
|
+
let se = W;
|
|
815
|
+
export {
|
|
816
|
+
se as ArgParser,
|
|
817
|
+
R as ArgParserError
|
|
818
|
+
};
|
|
819
|
+
//# sourceMappingURL=index.min.mjs.map
|