@alcyone-labs/arg-parser 3.0.0 → 3.0.1
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/dist/index.cjs +287 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.min.mjs +132 -282
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +280 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.min.mjs
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { z as
|
|
1
|
+
import $, { default as f } from "@alcyone-labs/simple-chalk";
|
|
2
|
+
import { z as r } from "zod";
|
|
3
3
|
import * as u from "node:path";
|
|
4
|
-
var b = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (t,
|
|
4
|
+
var b = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (t, n) => (typeof require < "u" ? require : t)[n] }) : e)(function(e) {
|
|
5
5
|
if (typeof require < "u") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Calling `require` for "' + e + "\" in an environment that doesn't expose the `require` function.");
|
|
7
|
-
})
|
|
8
|
-
const j = {
|
|
6
|
+
throw Error('Calling `require` for "' + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
7
|
+
}), N = {
|
|
9
8
|
NONE: "none",
|
|
10
9
|
DirectParentOnly: "direct-parent-only",
|
|
11
10
|
AllParents: "all-parents"
|
|
12
|
-
}, F =
|
|
13
|
-
sensitive:
|
|
14
|
-
localDefault:
|
|
15
|
-
type:
|
|
11
|
+
}, F = r.object({
|
|
12
|
+
sensitive: r.boolean().optional(),
|
|
13
|
+
localDefault: r.string().optional(),
|
|
14
|
+
type: r.enum([
|
|
16
15
|
"string",
|
|
17
16
|
"directory",
|
|
18
17
|
"file",
|
|
19
18
|
"boolean",
|
|
20
19
|
"number"
|
|
21
20
|
]).optional(),
|
|
22
|
-
multiple:
|
|
23
|
-
min:
|
|
24
|
-
max:
|
|
25
|
-
default:
|
|
26
|
-
title:
|
|
21
|
+
multiple: r.boolean().optional(),
|
|
22
|
+
min: r.number().optional(),
|
|
23
|
+
max: r.number().optional(),
|
|
24
|
+
default: r.any().optional(),
|
|
25
|
+
title: r.string().optional()
|
|
27
26
|
}).strict().refine((e) => e.min !== void 0 && e.max !== void 0 ? e.min <= e.max : !0, {
|
|
28
27
|
message: "min cannot be greater than max",
|
|
29
28
|
path: ["min"]
|
|
30
|
-
}),
|
|
31
|
-
name:
|
|
32
|
-
allowLigature:
|
|
33
|
-
allowMultiple:
|
|
34
|
-
description:
|
|
35
|
-
valueHint:
|
|
36
|
-
options:
|
|
37
|
-
defaultValue:
|
|
38
|
-
type:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
}), v = r.object({
|
|
30
|
+
name: r.string().min(1),
|
|
31
|
+
allowLigature: r.boolean().default(!0),
|
|
32
|
+
allowMultiple: r.boolean().default(!1),
|
|
33
|
+
description: r.union([r.string(), r.array(r.string())]).optional(),
|
|
34
|
+
valueHint: r.string().optional(),
|
|
35
|
+
options: r.array(r.string().min(1)).min(1),
|
|
36
|
+
defaultValue: r.any().optional(),
|
|
37
|
+
type: r.union([
|
|
38
|
+
r.custom((e) => e === String),
|
|
39
|
+
r.custom((e) => e === Number),
|
|
40
|
+
r.custom((e) => e === Boolean),
|
|
41
|
+
r.custom((e) => e === Array),
|
|
42
|
+
r.custom((e) => e === Object),
|
|
43
|
+
r.custom((e) => typeof e == "function"),
|
|
44
|
+
r.custom((e) => e && typeof e == "object" && e._def),
|
|
45
|
+
r.string()
|
|
47
46
|
]).default("string"),
|
|
48
|
-
mandatory:
|
|
49
|
-
flagOnly:
|
|
50
|
-
validate:
|
|
51
|
-
enum:
|
|
52
|
-
env:
|
|
47
|
+
mandatory: r.union([r.boolean(), r.custom((e) => typeof e == "function")]).optional(),
|
|
48
|
+
flagOnly: r.boolean().default(!1),
|
|
49
|
+
validate: r.custom((e) => typeof e == "function").optional(),
|
|
50
|
+
enum: r.array(r.any()).optional(),
|
|
51
|
+
env: r.union([r.string(), r.array(r.string())]).optional(),
|
|
53
52
|
dxtOptions: F.optional(),
|
|
54
|
-
dynamicRegister:
|
|
55
|
-
setWorkingDirectory:
|
|
56
|
-
positional:
|
|
57
|
-
prompt:
|
|
58
|
-
promptSequence:
|
|
53
|
+
dynamicRegister: r.custom((e) => typeof e == "function").optional(),
|
|
54
|
+
setWorkingDirectory: r.boolean().optional(),
|
|
55
|
+
positional: r.number().int().positive().optional(),
|
|
56
|
+
prompt: r.custom((e) => typeof e == "function").optional(),
|
|
57
|
+
promptSequence: r.number().int().positive().optional()
|
|
59
58
|
});
|
|
60
59
|
function O(e) {
|
|
61
60
|
if (e && typeof e == "object" && e._def) return "object";
|
|
@@ -77,147 +76,111 @@ function O(e) {
|
|
|
77
76
|
}
|
|
78
77
|
return "string";
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
successError: () =>
|
|
82
|
-
success:
|
|
83
|
-
message:
|
|
84
|
-
error:
|
|
79
|
+
var h = {
|
|
80
|
+
successError: () => r.object({
|
|
81
|
+
success: r.boolean(),
|
|
82
|
+
message: r.string().optional(),
|
|
83
|
+
error: r.string().optional()
|
|
85
84
|
}),
|
|
86
|
-
successWithData: (e) =>
|
|
87
|
-
success:
|
|
88
|
-
data: e ||
|
|
89
|
-
message:
|
|
90
|
-
error:
|
|
85
|
+
successWithData: (e) => r.object({
|
|
86
|
+
success: r.boolean(),
|
|
87
|
+
data: e || r.any(),
|
|
88
|
+
message: r.string().optional(),
|
|
89
|
+
error: r.string().optional()
|
|
91
90
|
}),
|
|
92
|
-
list: (e) =>
|
|
93
|
-
items:
|
|
94
|
-
count:
|
|
95
|
-
hasMore:
|
|
91
|
+
list: (e) => r.object({
|
|
92
|
+
items: r.array(e || r.any()),
|
|
93
|
+
count: r.number().optional(),
|
|
94
|
+
hasMore: r.boolean().optional()
|
|
96
95
|
}),
|
|
97
|
-
fileOperation: () =>
|
|
98
|
-
path:
|
|
99
|
-
size:
|
|
100
|
-
created:
|
|
101
|
-
modified:
|
|
102
|
-
exists:
|
|
96
|
+
fileOperation: () => r.object({
|
|
97
|
+
path: r.string(),
|
|
98
|
+
size: r.number().optional(),
|
|
99
|
+
created: r.boolean().optional(),
|
|
100
|
+
modified: r.boolean().optional(),
|
|
101
|
+
exists: r.boolean().optional()
|
|
103
102
|
}),
|
|
104
|
-
processExecution: () =>
|
|
105
|
-
exitCode:
|
|
106
|
-
stdout:
|
|
107
|
-
stderr:
|
|
108
|
-
duration:
|
|
109
|
-
command:
|
|
103
|
+
processExecution: () => r.object({
|
|
104
|
+
exitCode: r.number(),
|
|
105
|
+
stdout: r.string().optional(),
|
|
106
|
+
stderr: r.string().optional(),
|
|
107
|
+
duration: r.number().optional(),
|
|
108
|
+
command: r.string().optional()
|
|
110
109
|
})
|
|
111
110
|
};
|
|
112
111
|
function _(e) {
|
|
113
|
-
return typeof e == "string" && e in h ? h[e]() : e && typeof e == "object" && "_def" in e ? e : e && typeof e == "object" ?
|
|
112
|
+
return typeof e == "string" && e in h ? h[e]() : e && typeof e == "object" && "_def" in e ? e : e && typeof e == "object" ? r.object(e) : h.successError();
|
|
114
113
|
}
|
|
115
|
-
var
|
|
114
|
+
var w = class {
|
|
116
115
|
constructor(e = {}, t = []) {
|
|
117
116
|
this.flags = /* @__PURE__ */ new Map(), this.optionToFlagMap = /* @__PURE__ */ new Map(), this.options = {
|
|
118
117
|
throwForDuplicateFlags: !1,
|
|
119
118
|
...e
|
|
120
119
|
};
|
|
121
|
-
for (const
|
|
120
|
+
for (const n of t) this.addFlag(n);
|
|
122
121
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Add a single flag
|
|
125
|
-
*/
|
|
126
122
|
addFlag(e) {
|
|
127
123
|
const t = this.processFlag(e);
|
|
128
124
|
if (this.flags.has(t.name)) {
|
|
129
125
|
if (this.options.throwForDuplicateFlags) throw new Error(`Flag with name '${t.name}' already exists`);
|
|
130
126
|
console.warn(`[FlagManager] Flag '${t.name}' is being overwritten`);
|
|
131
127
|
}
|
|
132
|
-
for (const
|
|
133
|
-
const s = this.optionToFlagMap.get(
|
|
128
|
+
for (const n of t.options) {
|
|
129
|
+
const s = this.optionToFlagMap.get(n);
|
|
134
130
|
if (s && s !== t.name) {
|
|
135
|
-
if (this.options.throwForDuplicateFlags) throw new Error(`Option '${
|
|
136
|
-
console.warn(`[FlagManager] Option '${
|
|
131
|
+
if (this.options.throwForDuplicateFlags) throw new Error(`Option '${n}' is already used by flag '${s}'`);
|
|
132
|
+
console.warn(`[FlagManager] Option '${n}' is already used by flag '${s}'. Reassigning to '${t.name}'`);
|
|
137
133
|
}
|
|
138
|
-
this.optionToFlagMap.set(
|
|
134
|
+
this.optionToFlagMap.set(n, t.name);
|
|
139
135
|
}
|
|
140
136
|
this.flags.set(t.name, t);
|
|
141
137
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Add multiple flags
|
|
144
|
-
*/
|
|
145
138
|
addFlags(e) {
|
|
146
139
|
for (const t of e) this.addFlag(t);
|
|
147
140
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Remove a flag by name
|
|
150
|
-
*/
|
|
151
141
|
removeFlag(e) {
|
|
152
142
|
const t = this.flags.get(e);
|
|
153
143
|
if (!t) return !1;
|
|
154
|
-
for (const
|
|
144
|
+
for (const n of t.options) this.optionToFlagMap.delete(n);
|
|
155
145
|
return this.flags.delete(e);
|
|
156
146
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Check if a flag exists
|
|
159
|
-
*/
|
|
160
147
|
hasFlag(e) {
|
|
161
148
|
return this.flags.has(e);
|
|
162
149
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Get a flag by name
|
|
165
|
-
*/
|
|
166
150
|
getFlag(e) {
|
|
167
151
|
return this.flags.get(e);
|
|
168
152
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Get all flags as an array
|
|
171
|
-
*/
|
|
172
153
|
getAllFlags() {
|
|
173
154
|
return Array.from(this.flags.values());
|
|
174
155
|
}
|
|
175
|
-
/**
|
|
176
|
-
* Get all flag names
|
|
177
|
-
*/
|
|
178
156
|
getFlagNames() {
|
|
179
157
|
return Array.from(this.flags.keys());
|
|
180
158
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Find flag by option
|
|
183
|
-
*/
|
|
184
159
|
findFlagByOption(e) {
|
|
185
160
|
const t = this.optionToFlagMap.get(e);
|
|
186
161
|
if (t)
|
|
187
162
|
return this.flags.get(t);
|
|
188
163
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Process a raw flag into a ProcessedFlag
|
|
191
|
-
*/
|
|
192
164
|
processFlag(e) {
|
|
193
165
|
const t = { ...e };
|
|
194
|
-
return "default" in t && t.default !== void 0 && !("defaultValue" in t) && (t.defaultValue = t.default), "required" in t && t.required !== void 0 && !("mandatory" in t) && (t.mandatory = t.required),
|
|
166
|
+
return "default" in t && t.default !== void 0 && !("defaultValue" in t) && (t.defaultValue = t.default), "required" in t && t.required !== void 0 && !("mandatory" in t) && (t.mandatory = t.required), v.parse(t);
|
|
195
167
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Internal method to set a processed flag directly (for inheritance)
|
|
198
|
-
*/
|
|
199
168
|
_setProcessedFlagForInheritance(e) {
|
|
200
169
|
this.flags.set(e.name, e);
|
|
201
170
|
for (const t of e.options) this.optionToFlagMap.set(t, e.name);
|
|
202
171
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Clear all flags
|
|
205
|
-
*/
|
|
206
172
|
clear() {
|
|
207
173
|
this.flags.clear(), this.optionToFlagMap.clear();
|
|
208
174
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Get collision report
|
|
211
|
-
*/
|
|
212
175
|
getCollisions() {
|
|
213
176
|
const e = [], t = /* @__PURE__ */ new Map();
|
|
214
|
-
for (const [
|
|
177
|
+
for (const [n, s] of this.flags) for (const a of s.options) {
|
|
215
178
|
const o = t.get(a);
|
|
216
|
-
o && o !==
|
|
217
|
-
flagName:
|
|
179
|
+
o && o !== n && e.push({
|
|
180
|
+
flagName: n,
|
|
218
181
|
option: a,
|
|
219
182
|
existingFlagName: o
|
|
220
|
-
}), t.set(a,
|
|
183
|
+
}), t.set(a, n);
|
|
221
184
|
}
|
|
222
185
|
return e;
|
|
223
186
|
}
|
|
@@ -231,38 +194,20 @@ var v = class {
|
|
|
231
194
|
get sequenceOffset() {
|
|
232
195
|
return this._options.sequenceOffset ?? 0;
|
|
233
196
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Register a promptable flag
|
|
236
|
-
*/
|
|
237
197
|
registerPromptableFlag(e) {
|
|
238
198
|
this.promptableFlags.set(e.name, e);
|
|
239
199
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Unregister a promptable flag
|
|
242
|
-
*/
|
|
243
200
|
unregisterPromptableFlag(e) {
|
|
244
201
|
return this.promptableFlags.delete(e);
|
|
245
202
|
}
|
|
246
|
-
/**
|
|
247
|
-
* Check if a flag has a prompt
|
|
248
|
-
*/
|
|
249
203
|
hasPrompt(e) {
|
|
250
204
|
return this.promptableFlags.has(e);
|
|
251
205
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Get all promptable flags sorted by sequence
|
|
254
|
-
*/
|
|
255
206
|
getPromptableFlags() {
|
|
256
207
|
return Array.from(this.promptableFlags.values()).sort((e, t) => (e.promptSequence ?? 1 / 0) - (t.promptSequence ?? 1 / 0));
|
|
257
208
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Execute prompts for missing flags
|
|
260
|
-
*
|
|
261
|
-
* This is a placeholder implementation. The actual implementation
|
|
262
|
-
* would integrate with @clack/prompts.
|
|
263
|
-
*/
|
|
264
209
|
async executePrompts(e, t) {
|
|
265
|
-
const
|
|
210
|
+
const n = {}, s = [];
|
|
266
211
|
for (const a of t) {
|
|
267
212
|
const o = this.promptableFlags.get(a);
|
|
268
213
|
if (!(!o || !o.prompt))
|
|
@@ -282,14 +227,11 @@ var v = class {
|
|
|
282
227
|
}
|
|
283
228
|
}
|
|
284
229
|
return {
|
|
285
|
-
answers:
|
|
230
|
+
answers: n,
|
|
286
231
|
results: s,
|
|
287
232
|
cancelled: !1
|
|
288
233
|
};
|
|
289
234
|
}
|
|
290
|
-
/**
|
|
291
|
-
* Clear all registered flags
|
|
292
|
-
*/
|
|
293
235
|
clear() {
|
|
294
236
|
this.promptableFlags.clear();
|
|
295
237
|
}
|
|
@@ -298,11 +240,11 @@ var v = class {
|
|
|
298
240
|
super(e), this.cmdChain = t, this.name = "ArgParserError", this.commandChain = t;
|
|
299
241
|
}
|
|
300
242
|
}, q = class {
|
|
301
|
-
#
|
|
243
|
+
#r = "Argument Parser";
|
|
302
244
|
#i;
|
|
303
245
|
#l = "";
|
|
304
246
|
#o;
|
|
305
|
-
#
|
|
247
|
+
#n;
|
|
306
248
|
#t = /* @__PURE__ */ new Map();
|
|
307
249
|
#e;
|
|
308
250
|
#u;
|
|
@@ -316,119 +258,71 @@ var v = class {
|
|
|
316
258
|
#d;
|
|
317
259
|
#m = null;
|
|
318
260
|
constructor(e = {}, t) {
|
|
319
|
-
if (this.#
|
|
261
|
+
if (this.#r = e.appName || "app", this.#i = e.appCommandName, this.#o = e.description, this.#n = e.handler, e.mandatoryCharacter !== void 0 && (this.#c = e.mandatoryCharacter), e.throwForDuplicateFlags !== void 0 && (this.#g = e.throwForDuplicateFlags), e.handleErrors !== void 0 && (this.#f = e.handleErrors), e.autoExit !== void 0 && (this.#a = e.autoExit), e.inheritParentFlags !== void 0 && (this.#p = e.inheritParentFlags), e.promptWhen !== void 0 && (this.#h = e.promptWhen), this.#e = new w({ throwForDuplicateFlags: this.#g }, t || []), this.#u = new P(), this.addFlag({
|
|
320
262
|
name: "help",
|
|
321
263
|
description: "Display this help message and exit",
|
|
322
264
|
mandatory: !1,
|
|
323
265
|
type: Boolean,
|
|
324
266
|
options: ["-h", "--help"],
|
|
325
267
|
flagOnly: !0
|
|
326
|
-
}), e.subCommands) for (const
|
|
268
|
+
}), e.subCommands) for (const n of e.subCommands) this.addSubCommand(n);
|
|
327
269
|
}
|
|
328
|
-
/**
|
|
329
|
-
* Install a plugin
|
|
330
|
-
*/
|
|
331
270
|
use(e) {
|
|
332
271
|
if (this.#s.has(e.name)) throw new Error(`Plugin '${e.name}' is already installed`);
|
|
333
272
|
const t = e.install(this);
|
|
334
273
|
return this.#s.set(e.name, e), t || this;
|
|
335
274
|
}
|
|
336
|
-
/**
|
|
337
|
-
* Check if a plugin is installed
|
|
338
|
-
*/
|
|
339
275
|
hasPlugin(e) {
|
|
340
276
|
return this.#s.has(e);
|
|
341
277
|
}
|
|
342
|
-
/**
|
|
343
|
-
* Get an installed plugin
|
|
344
|
-
*/
|
|
345
278
|
getPlugin(e) {
|
|
346
279
|
return this.#s.get(e);
|
|
347
280
|
}
|
|
348
|
-
/**
|
|
349
|
-
* List all installed plugins
|
|
350
|
-
*/
|
|
351
281
|
listPlugins() {
|
|
352
282
|
return Array.from(this.#s.keys());
|
|
353
283
|
}
|
|
354
|
-
/**
|
|
355
|
-
* Add a flag
|
|
356
|
-
*/
|
|
357
284
|
addFlag(e) {
|
|
358
285
|
return this.#e.addFlag(e), "prompt" in e && typeof e.prompt == "function" && this.#u.registerPromptableFlag(e), this;
|
|
359
286
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Add multiple flags
|
|
362
|
-
*/
|
|
363
287
|
addFlags(e) {
|
|
364
288
|
for (const t of e) this.addFlag(t);
|
|
365
289
|
return this;
|
|
366
290
|
}
|
|
367
|
-
/**
|
|
368
|
-
* Check if a flag exists
|
|
369
|
-
*/
|
|
370
291
|
hasFlag(e) {
|
|
371
292
|
return this.#e.hasFlag(e);
|
|
372
293
|
}
|
|
373
|
-
/**
|
|
374
|
-
* Get a flag definition
|
|
375
|
-
*/
|
|
376
294
|
getFlagDefinition(e) {
|
|
377
295
|
return this.#e.getFlag(e);
|
|
378
296
|
}
|
|
379
|
-
/**
|
|
380
|
-
* Get all flags
|
|
381
|
-
*/
|
|
382
297
|
get flags() {
|
|
383
298
|
return this.#e.getAllFlags();
|
|
384
299
|
}
|
|
385
|
-
/**
|
|
386
|
-
* Get all flag names
|
|
387
|
-
*/
|
|
388
300
|
get flagNames() {
|
|
389
301
|
return this.#e.getFlagNames();
|
|
390
302
|
}
|
|
391
|
-
/**
|
|
392
|
-
* Add a subcommand
|
|
393
|
-
*/
|
|
394
303
|
addSubCommand(e) {
|
|
395
304
|
if (this.#t.has(e.name)) throw new Error(`Subcommand '${e.name}' already exists`);
|
|
396
305
|
const t = e.parser;
|
|
397
306
|
return t && (t.#d = this, t.#l = e.name, t.#p && this.inheritFlagsToSubParser(t)), this.#t.set(e.name, e), this;
|
|
398
307
|
}
|
|
399
|
-
/**
|
|
400
|
-
* Get a subcommand
|
|
401
|
-
*/
|
|
402
308
|
getSubCommand(e) {
|
|
403
309
|
return this.#t.get(e);
|
|
404
310
|
}
|
|
405
|
-
/**
|
|
406
|
-
* Get all subcommands
|
|
407
|
-
*/
|
|
408
311
|
getSubCommands() {
|
|
409
312
|
return new Map(this.#t);
|
|
410
313
|
}
|
|
411
|
-
/**
|
|
412
|
-
* Inherit flags to a sub-parser
|
|
413
|
-
*/
|
|
414
314
|
inheritFlagsToSubParser(e) {
|
|
415
315
|
const t = this.#e.getAllFlags();
|
|
416
|
-
for (const
|
|
316
|
+
for (const n of t) e.hasFlag(n.name) || e.#e._setProcessedFlagForInheritance(n);
|
|
417
317
|
}
|
|
418
|
-
/**
|
|
419
|
-
* Set the handler
|
|
420
|
-
*/
|
|
421
318
|
setHandler(e) {
|
|
422
|
-
return this.#
|
|
319
|
+
return this.#n = e, this;
|
|
423
320
|
}
|
|
424
|
-
/**
|
|
425
|
-
* Get the handler
|
|
426
|
-
*/
|
|
427
321
|
getHandler() {
|
|
428
|
-
return this.#
|
|
322
|
+
return this.#n;
|
|
429
323
|
}
|
|
430
324
|
getAppName() {
|
|
431
|
-
return this.#
|
|
325
|
+
return this.#r;
|
|
432
326
|
}
|
|
433
327
|
getAppCommandName() {
|
|
434
328
|
return this.#i;
|
|
@@ -445,13 +339,10 @@ var v = class {
|
|
|
445
339
|
getPromptWhen() {
|
|
446
340
|
return this.#h;
|
|
447
341
|
}
|
|
448
|
-
/**
|
|
449
|
-
* Parse command line arguments
|
|
450
|
-
*/
|
|
451
342
|
async parse(e, t = {}) {
|
|
452
|
-
const
|
|
343
|
+
const n = e || process.argv.slice(2);
|
|
453
344
|
try {
|
|
454
|
-
const { systemArgs: s, filteredArgs: a } = this.detectAndStripSystemFlags(
|
|
345
|
+
const { systemArgs: s, filteredArgs: a } = this.detectAndStripSystemFlags(n);
|
|
455
346
|
if (!t.skipHelpHandling && a.includes("--help"))
|
|
456
347
|
return console.log(this.helpText()), this.handleExit(0, "Help displayed", "help");
|
|
457
348
|
const { finalParser: o, commandChain: i, remainingArgs: l } = this.findCommandChain(a), c = await o.parseFlags(l, t), g = {
|
|
@@ -465,7 +356,7 @@ var v = class {
|
|
|
465
356
|
systemArgs: s,
|
|
466
357
|
logger: console
|
|
467
358
|
};
|
|
468
|
-
return o.#
|
|
359
|
+
return o.#n && !t.skipHandlers ? await o.#n(g) : c;
|
|
469
360
|
} catch (s) {
|
|
470
361
|
if (s instanceof d) {
|
|
471
362
|
if (!this.#f) throw s;
|
|
@@ -474,63 +365,51 @@ var v = class {
|
|
|
474
365
|
throw s;
|
|
475
366
|
}
|
|
476
367
|
}
|
|
477
|
-
/**
|
|
478
|
-
* Parse flags only
|
|
479
|
-
*/
|
|
480
368
|
async parseFlags(e, t = {}) {
|
|
481
|
-
const
|
|
482
|
-
for (const i of s) i.defaultValue !== void 0 && (
|
|
369
|
+
const n = {}, s = this.#e.getAllFlags();
|
|
370
|
+
for (const i of s) i.defaultValue !== void 0 && (n[i.name] = i.defaultValue);
|
|
483
371
|
let a = 0;
|
|
484
372
|
for (; a < e.length; ) {
|
|
485
373
|
const i = e[a], l = this.#e.findFlagByOption(i);
|
|
486
|
-
if (l) if (l.flagOnly)
|
|
374
|
+
if (l) if (l.flagOnly) n[l.name] = !0;
|
|
487
375
|
else {
|
|
488
376
|
const c = e[a + 1];
|
|
489
377
|
if (c && !c.startsWith("-")) {
|
|
490
378
|
const g = this.parseFlagValue(c, l.type);
|
|
491
|
-
l.allowMultiple ? (Array.isArray(
|
|
492
|
-
} else l.type === Boolean && (
|
|
379
|
+
l.allowMultiple ? (Array.isArray(n[l.name]) || (n[l.name] = n[l.name] !== void 0 ? [n[l.name]] : []), n[l.name].push(g)) : n[l.name] = g, a++;
|
|
380
|
+
} else l.type === Boolean && (n[l.name] = !0);
|
|
493
381
|
}
|
|
494
382
|
a++;
|
|
495
383
|
}
|
|
496
|
-
for (const i of s) if (i.enum && i.enum.length > 0 &&
|
|
497
|
-
const l =
|
|
498
|
-
if (!i.enum.includes(l)) throw new d(`Invalid value '${l}' for flag '${i.name}'. Allowed values: ${i.enum.join(", ")}`, [this.#
|
|
384
|
+
for (const i of s) if (i.enum && i.enum.length > 0 && n[i.name] !== void 0) {
|
|
385
|
+
const l = n[i.name];
|
|
386
|
+
if (!i.enum.includes(l)) throw new d(`Invalid value '${l}' for flag '${i.name}'. Allowed values: ${i.enum.join(", ")}`, [this.#r]);
|
|
499
387
|
}
|
|
500
388
|
const o = [];
|
|
501
|
-
for (const i of s) i.mandatory &&
|
|
502
|
-
if (o.length > 0) throw new d(`Missing mandatory flags: ${o.join(", ")}`, [this.#
|
|
503
|
-
return
|
|
389
|
+
for (const i of s) i.mandatory && n[i.name] === void 0 && (typeof i.mandatory == "function" ? i.mandatory(n) && o.push(i.name) : o.push(i.name));
|
|
390
|
+
if (o.length > 0) throw new d(`Missing mandatory flags: ${o.join(", ")}`, [this.#r]);
|
|
391
|
+
return n;
|
|
504
392
|
}
|
|
505
|
-
/**
|
|
506
|
-
* Parse a flag value based on type
|
|
507
|
-
*/
|
|
508
393
|
parseFlagValue(e, t) {
|
|
509
394
|
return t === Boolean || t === "boolean" ? /^(true|yes|1)$/i.test(e) : t === Number || t === "number" ? Number(e) : t === String || t === "string" ? e : typeof t == "function" ? t(e) : e;
|
|
510
395
|
}
|
|
511
|
-
/**
|
|
512
|
-
* Find the command chain for subcommands
|
|
513
|
-
*/
|
|
514
396
|
findCommandChain(e) {
|
|
515
397
|
let t = this;
|
|
516
|
-
const
|
|
398
|
+
const n = [];
|
|
517
399
|
let s = [...e];
|
|
518
400
|
for (; s.length > 0; ) {
|
|
519
401
|
const a = s[0], o = t.#t.get(a);
|
|
520
402
|
if (!o) break;
|
|
521
|
-
|
|
403
|
+
n.push(a), t = o.parser, s = s.slice(1);
|
|
522
404
|
}
|
|
523
405
|
return {
|
|
524
406
|
finalParser: t,
|
|
525
|
-
commandChain:
|
|
407
|
+
commandChain: n,
|
|
526
408
|
remainingArgs: s
|
|
527
409
|
};
|
|
528
410
|
}
|
|
529
|
-
/**
|
|
530
|
-
* Detect and strip system flags
|
|
531
|
-
*/
|
|
532
411
|
detectAndStripSystemFlags(e) {
|
|
533
|
-
const t = {},
|
|
412
|
+
const t = {}, n = [];
|
|
534
413
|
for (let s = 0; s < e.length; s++) {
|
|
535
414
|
const a = e[s], o = e[s + 1];
|
|
536
415
|
switch (a) {
|
|
@@ -541,39 +420,33 @@ var v = class {
|
|
|
541
420
|
t.withEnv = o && !o.startsWith("-") ? o : !0, o && !o.startsWith("-") && s++;
|
|
542
421
|
break;
|
|
543
422
|
default:
|
|
544
|
-
|
|
423
|
+
n.push(a);
|
|
545
424
|
}
|
|
546
425
|
}
|
|
547
426
|
return {
|
|
548
427
|
systemArgs: t,
|
|
549
|
-
filteredArgs:
|
|
428
|
+
filteredArgs: n
|
|
550
429
|
};
|
|
551
430
|
}
|
|
552
|
-
|
|
553
|
-
* Handle exit
|
|
554
|
-
*/
|
|
555
|
-
handleExit(e, t, r) {
|
|
431
|
+
handleExit(e, t, n) {
|
|
556
432
|
const s = {
|
|
557
433
|
success: e === 0,
|
|
558
434
|
exitCode: e,
|
|
559
435
|
message: t,
|
|
560
|
-
type:
|
|
436
|
+
type: n || (e === 0 ? "success" : "error"),
|
|
561
437
|
shouldExit: !0
|
|
562
438
|
};
|
|
563
439
|
return this.#a && typeof process < "u" && process.exit && process.exit(e), s;
|
|
564
440
|
}
|
|
565
|
-
/**
|
|
566
|
-
* Generate help text
|
|
567
|
-
*/
|
|
568
441
|
helpText() {
|
|
569
442
|
const e = [];
|
|
570
|
-
e.push(f.bold(this.#
|
|
571
|
-
const t = this.#i || this.#
|
|
443
|
+
e.push(f.bold(this.#r)), this.#o && e.push(this.#o), e.push("");
|
|
444
|
+
const t = this.#i || this.#r.toLowerCase();
|
|
572
445
|
e.push(f.bold("Usage:")), e.push(` ${t} [options] [command]`), e.push("");
|
|
573
|
-
const
|
|
574
|
-
if (
|
|
446
|
+
const n = this.#e.getAllFlags();
|
|
447
|
+
if (n.length > 0) {
|
|
575
448
|
e.push(f.bold("Options:"));
|
|
576
|
-
for (const s of
|
|
449
|
+
for (const s of n) {
|
|
577
450
|
const a = s.options.join(", "), o = s.defaultValue !== void 0 ? ` (default: ${s.defaultValue})` : "", i = s.mandatory ? ` ${this.#c}` : "";
|
|
578
451
|
e.push(` ${a.padEnd(20)} ${s.description || ""}${o}${i}`);
|
|
579
452
|
}
|
|
@@ -591,9 +464,6 @@ var v = class {
|
|
|
591
464
|
constructor() {
|
|
592
465
|
this.plugins = /* @__PURE__ */ new Map(), this.metadata = /* @__PURE__ */ new Map();
|
|
593
466
|
}
|
|
594
|
-
/**
|
|
595
|
-
* Register a plugin in the registry
|
|
596
|
-
*/
|
|
597
467
|
register(e, t) {
|
|
598
468
|
if (this.plugins.has(e.name)) {
|
|
599
469
|
console.warn(`[ArgParser] Plugin '${e.name}' is already registered`);
|
|
@@ -601,48 +471,29 @@ var v = class {
|
|
|
601
471
|
}
|
|
602
472
|
this.plugins.set(e.name, e), t && this.metadata.set(e.name, t);
|
|
603
473
|
}
|
|
604
|
-
/**
|
|
605
|
-
* Get a registered plugin by name
|
|
606
|
-
*/
|
|
607
474
|
get(e) {
|
|
608
475
|
return this.plugins.get(e);
|
|
609
476
|
}
|
|
610
|
-
/**
|
|
611
|
-
* Check if a plugin is registered
|
|
612
|
-
*/
|
|
613
477
|
has(e) {
|
|
614
478
|
return this.plugins.has(e);
|
|
615
479
|
}
|
|
616
|
-
/**
|
|
617
|
-
* List all registered plugin names
|
|
618
|
-
*/
|
|
619
480
|
list() {
|
|
620
481
|
return Array.from(this.plugins.keys());
|
|
621
482
|
}
|
|
622
|
-
/**
|
|
623
|
-
* Get metadata for a plugin
|
|
624
|
-
*/
|
|
625
483
|
getMetadata(e) {
|
|
626
484
|
return this.metadata.get(e);
|
|
627
485
|
}
|
|
628
|
-
/**
|
|
629
|
-
* Unregister a plugin
|
|
630
|
-
*/
|
|
631
486
|
unregister(e) {
|
|
632
487
|
const t = this.plugins.get(e);
|
|
633
488
|
return t?.destroy && t.destroy(), this.metadata.delete(e), this.plugins.delete(e);
|
|
634
489
|
}
|
|
635
|
-
/**
|
|
636
|
-
* Clear all registered plugins
|
|
637
|
-
*/
|
|
638
490
|
clear() {
|
|
639
491
|
for (const [, e] of this.plugins) e.destroy && e.destroy();
|
|
640
492
|
this.plugins.clear(), this.metadata.clear();
|
|
641
493
|
}
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
return r.value._isExposed = !0, r.value._exposedName = t, r;
|
|
494
|
+
}, R = new A();
|
|
495
|
+
function W(e, t, n) {
|
|
496
|
+
return n.value._isExposed = !0, n.value._exposedName = t, n;
|
|
646
497
|
}
|
|
647
498
|
var m = class {
|
|
648
499
|
}, E = class extends m {
|
|
@@ -679,8 +530,7 @@ var m = class {
|
|
|
679
530
|
findForSource(e) {
|
|
680
531
|
for (const t of this.plugins.values()) if (t.canLoad(e)) return t;
|
|
681
532
|
}
|
|
682
|
-
};
|
|
683
|
-
const y = new S();
|
|
533
|
+
}, y = new S();
|
|
684
534
|
y.register(new E());
|
|
685
535
|
y.register(new x());
|
|
686
536
|
async function C() {
|
|
@@ -690,7 +540,7 @@ async function B() {
|
|
|
690
540
|
}
|
|
691
541
|
function k() {
|
|
692
542
|
}
|
|
693
|
-
|
|
543
|
+
var G = {
|
|
694
544
|
log: (...e) => {
|
|
695
545
|
(process.env.DEBUG || process.env.ARG_PARSER_DEBUG) && console.log("[ArgParser Debug]", ...e);
|
|
696
546
|
},
|
|
@@ -722,15 +572,15 @@ function H(e) {
|
|
|
722
572
|
const i = p(), l = u.dirname(i);
|
|
723
573
|
return u.resolve(l, e);
|
|
724
574
|
}
|
|
725
|
-
const { path: t, relativeTo:
|
|
726
|
-
if (
|
|
727
|
-
if (
|
|
575
|
+
const { path: t, relativeTo: n = "entry", basePath: s } = e;
|
|
576
|
+
if (n === "absolute") return t;
|
|
577
|
+
if (n === "cwd") return u.resolve(process.cwd(), t);
|
|
728
578
|
const a = s || p(), o = u.dirname(a);
|
|
729
579
|
return u.resolve(o, t);
|
|
730
580
|
}
|
|
731
581
|
function L(e) {
|
|
732
|
-
const t = p(),
|
|
733
|
-
return u.resolve(
|
|
582
|
+
const t = p(), n = u.dirname(t);
|
|
583
|
+
return u.resolve(n, e);
|
|
734
584
|
}
|
|
735
585
|
function M(e) {
|
|
736
586
|
return u.resolve(process.cwd(), e);
|
|
@@ -747,13 +597,13 @@ export {
|
|
|
747
597
|
m as ConfigPlugin,
|
|
748
598
|
S as ConfigPluginRegistry,
|
|
749
599
|
x as EnvConfigPlugin,
|
|
750
|
-
|
|
751
|
-
|
|
600
|
+
N as FlagInheritance,
|
|
601
|
+
w as FlagManager,
|
|
752
602
|
E as JsonConfigPlugin,
|
|
753
603
|
h as OutputSchemaPatterns,
|
|
754
604
|
A as PluginRegistry,
|
|
755
605
|
P as PromptManager,
|
|
756
|
-
|
|
606
|
+
$ as SimpleChalk,
|
|
757
607
|
U as absolutePath,
|
|
758
608
|
_ as createOutputSchema,
|
|
759
609
|
M as cwdRelative,
|
|
@@ -771,7 +621,7 @@ export {
|
|
|
771
621
|
I as legacyCwdPath,
|
|
772
622
|
H as resolveLogPath,
|
|
773
623
|
F as zodDxtOptionsSchema,
|
|
774
|
-
|
|
624
|
+
v as zodFlagSchema
|
|
775
625
|
};
|
|
776
626
|
|
|
777
627
|
//# sourceMappingURL=index.min.mjs.map
|