@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.mjs
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import SimpleChalk, { default as chalk } from "@alcyone-labs/simple-chalk";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
4
5
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
5
6
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function.");
|
|
7
|
+
throw Error("Calling `require` for \"" + x + "\" 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
8
|
});
|
|
8
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/core/types.ts
|
|
11
|
+
/**
|
|
12
|
+
* Core types for ArgParser
|
|
13
|
+
*
|
|
14
|
+
* These types define the shape of flags, commands, and configuration
|
|
15
|
+
* for the argument parser.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Defines the behavior for flag inheritance in sub-commands.
|
|
19
|
+
*/
|
|
20
|
+
var FlagInheritance = {
|
|
9
21
|
NONE: "none",
|
|
10
22
|
DirectParentOnly: "direct-parent-only",
|
|
11
23
|
AllParents: "all-parents"
|
|
12
24
|
};
|
|
13
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Zod schema for validating DXT-specific options
|
|
27
|
+
*/
|
|
28
|
+
var zodDxtOptionsSchema = z.object({
|
|
14
29
|
sensitive: z.boolean().optional(),
|
|
15
30
|
localDefault: z.string().optional(),
|
|
16
31
|
type: z.enum([
|
|
@@ -32,7 +47,7 @@ const zodDxtOptionsSchema = z.object({
|
|
|
32
47
|
message: "min cannot be greater than max",
|
|
33
48
|
path: ["min"]
|
|
34
49
|
});
|
|
35
|
-
|
|
50
|
+
var zodFlagSchema = z.object({
|
|
36
51
|
name: z.string().min(1),
|
|
37
52
|
allowLigature: z.boolean().default(true),
|
|
38
53
|
allowMultiple: z.boolean().default(false),
|
|
@@ -82,7 +97,7 @@ function getJsonSchemaTypeFromFlag(flagType) {
|
|
|
82
97
|
}
|
|
83
98
|
return "string";
|
|
84
99
|
}
|
|
85
|
-
|
|
100
|
+
var OutputSchemaPatterns = {
|
|
86
101
|
successError: () => z.object({
|
|
87
102
|
success: z.boolean(),
|
|
88
103
|
message: z.string().optional(),
|
|
@@ -120,6 +135,17 @@ function createOutputSchema(pattern) {
|
|
|
120
135
|
if (pattern && typeof pattern === "object") return z.object(pattern);
|
|
121
136
|
return OutputSchemaPatterns.successError();
|
|
122
137
|
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/core/FlagManager.ts
|
|
140
|
+
/**
|
|
141
|
+
* FlagManager - Manages flag definitions and collision detection
|
|
142
|
+
*
|
|
143
|
+
* This class handles the registration, storage, and retrieval of CLI flags.
|
|
144
|
+
* It provides collision detection to prevent duplicate flag definitions.
|
|
145
|
+
*/
|
|
146
|
+
/**
|
|
147
|
+
* Manages flag definitions for an ArgParser instance
|
|
148
|
+
*/
|
|
123
149
|
var FlagManager = class {
|
|
124
150
|
constructor(options = {}, initialFlags = []) {
|
|
125
151
|
this.flags = /* @__PURE__ */ new Map();
|
|
@@ -130,6 +156,9 @@ var FlagManager = class {
|
|
|
130
156
|
};
|
|
131
157
|
for (const flag of initialFlags) this.addFlag(flag);
|
|
132
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Add a single flag
|
|
161
|
+
*/
|
|
133
162
|
addFlag(flag) {
|
|
134
163
|
const processedFlag = this.processFlag(flag);
|
|
135
164
|
if (this.flags.has(processedFlag.name)) {
|
|
@@ -146,46 +175,79 @@ var FlagManager = class {
|
|
|
146
175
|
}
|
|
147
176
|
this.flags.set(processedFlag.name, processedFlag);
|
|
148
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Add multiple flags
|
|
180
|
+
*/
|
|
149
181
|
addFlags(flags) {
|
|
150
182
|
for (const flag of flags) this.addFlag(flag);
|
|
151
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Remove a flag by name
|
|
186
|
+
*/
|
|
152
187
|
removeFlag(name) {
|
|
153
188
|
const flag = this.flags.get(name);
|
|
154
189
|
if (!flag) return false;
|
|
155
190
|
for (const option of flag.options) this.optionToFlagMap.delete(option);
|
|
156
191
|
return this.flags.delete(name);
|
|
157
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Check if a flag exists
|
|
195
|
+
*/
|
|
158
196
|
hasFlag(name) {
|
|
159
197
|
return this.flags.has(name);
|
|
160
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Get a flag by name
|
|
201
|
+
*/
|
|
161
202
|
getFlag(name) {
|
|
162
203
|
return this.flags.get(name);
|
|
163
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Get all flags as an array
|
|
207
|
+
*/
|
|
164
208
|
getAllFlags() {
|
|
165
209
|
return Array.from(this.flags.values());
|
|
166
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Get all flag names
|
|
213
|
+
*/
|
|
167
214
|
getFlagNames() {
|
|
168
215
|
return Array.from(this.flags.keys());
|
|
169
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Find flag by option
|
|
219
|
+
*/
|
|
170
220
|
findFlagByOption(option) {
|
|
171
221
|
const flagName = this.optionToFlagMap.get(option);
|
|
172
222
|
if (!flagName) return void 0;
|
|
173
223
|
return this.flags.get(flagName);
|
|
174
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Process a raw flag into a ProcessedFlag
|
|
227
|
+
*/
|
|
175
228
|
processFlag(flag) {
|
|
176
229
|
const rawFlag = { ...flag };
|
|
177
230
|
if ("default" in rawFlag && rawFlag.default !== void 0 && !("defaultValue" in rawFlag)) rawFlag.defaultValue = rawFlag.default;
|
|
178
231
|
if ("required" in rawFlag && rawFlag.required !== void 0 && !("mandatory" in rawFlag)) rawFlag.mandatory = rawFlag.required;
|
|
179
232
|
return zodFlagSchema.parse(rawFlag);
|
|
180
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Internal method to set a processed flag directly (for inheritance)
|
|
236
|
+
*/
|
|
181
237
|
_setProcessedFlagForInheritance(flag) {
|
|
182
238
|
this.flags.set(flag.name, flag);
|
|
183
239
|
for (const option of flag.options) this.optionToFlagMap.set(option, flag.name);
|
|
184
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Clear all flags
|
|
243
|
+
*/
|
|
185
244
|
clear() {
|
|
186
245
|
this.flags.clear();
|
|
187
246
|
this.optionToFlagMap.clear();
|
|
188
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Get collision report
|
|
250
|
+
*/
|
|
189
251
|
getCollisions() {
|
|
190
252
|
const collisions = [];
|
|
191
253
|
const seen = /* @__PURE__ */ new Map();
|
|
@@ -201,6 +263,11 @@ var FlagManager = class {
|
|
|
201
263
|
return collisions;
|
|
202
264
|
}
|
|
203
265
|
};
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/core/PromptManager.ts
|
|
268
|
+
/**
|
|
269
|
+
* Manages interactive prompts for an ArgParser instance
|
|
270
|
+
*/
|
|
204
271
|
var PromptManager = class {
|
|
205
272
|
constructor(options = {}) {
|
|
206
273
|
this.promptableFlags = /* @__PURE__ */ new Map();
|
|
@@ -212,20 +279,38 @@ var PromptManager = class {
|
|
|
212
279
|
get sequenceOffset() {
|
|
213
280
|
return this._options.sequenceOffset ?? 0;
|
|
214
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Register a promptable flag
|
|
284
|
+
*/
|
|
215
285
|
registerPromptableFlag(flag) {
|
|
216
286
|
this.promptableFlags.set(flag.name, flag);
|
|
217
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Unregister a promptable flag
|
|
290
|
+
*/
|
|
218
291
|
unregisterPromptableFlag(name) {
|
|
219
292
|
return this.promptableFlags.delete(name);
|
|
220
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Check if a flag has a prompt
|
|
296
|
+
*/
|
|
221
297
|
hasPrompt(name) {
|
|
222
298
|
return this.promptableFlags.has(name);
|
|
223
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Get all promptable flags sorted by sequence
|
|
302
|
+
*/
|
|
224
303
|
getPromptableFlags() {
|
|
225
304
|
return Array.from(this.promptableFlags.values()).sort((a, b) => {
|
|
226
305
|
return (a.promptSequence ?? Infinity) - (b.promptSequence ?? Infinity);
|
|
227
306
|
});
|
|
228
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Execute prompts for missing flags
|
|
310
|
+
*
|
|
311
|
+
* This is a placeholder implementation. The actual implementation
|
|
312
|
+
* would integrate with @clack/prompts.
|
|
313
|
+
*/
|
|
229
314
|
async executePrompts(context, missingFlagNames) {
|
|
230
315
|
const answers = {};
|
|
231
316
|
const results = [];
|
|
@@ -254,10 +339,24 @@ var PromptManager = class {
|
|
|
254
339
|
cancelled: false
|
|
255
340
|
};
|
|
256
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Clear all registered flags
|
|
344
|
+
*/
|
|
257
345
|
clear() {
|
|
258
346
|
this.promptableFlags.clear();
|
|
259
347
|
}
|
|
260
348
|
};
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/core/ArgParser.ts
|
|
351
|
+
/**
|
|
352
|
+
* Core ArgParser implementation
|
|
353
|
+
*
|
|
354
|
+
* This is the main ArgParser class with full CLI parsing capabilities.
|
|
355
|
+
* It has NO dependencies on MCP, DXT, or TUI - those are provided by plugins.
|
|
356
|
+
*/
|
|
357
|
+
/**
|
|
358
|
+
* Error thrown by ArgParser
|
|
359
|
+
*/
|
|
261
360
|
var ArgParserError = class extends Error {
|
|
262
361
|
constructor(message, cmdChain = []) {
|
|
263
362
|
super(message);
|
|
@@ -266,6 +365,16 @@ var ArgParserError = class extends Error {
|
|
|
266
365
|
this.commandChain = cmdChain;
|
|
267
366
|
}
|
|
268
367
|
};
|
|
368
|
+
/**
|
|
369
|
+
* Core ArgParser class
|
|
370
|
+
*
|
|
371
|
+
* Provides complete CLI argument parsing with support for:
|
|
372
|
+
* - Flags (with types, validation, defaults)
|
|
373
|
+
* - Subcommands
|
|
374
|
+
* - Interactive prompts
|
|
375
|
+
* - Help generation
|
|
376
|
+
* - Plugin system
|
|
377
|
+
*/
|
|
269
378
|
var ArgParser = class {
|
|
270
379
|
#appName = "Argument Parser";
|
|
271
380
|
#appCommandName;
|
|
@@ -307,42 +416,75 @@ var ArgParser = class {
|
|
|
307
416
|
});
|
|
308
417
|
if (params.subCommands) for (const sub of params.subCommands) this.addSubCommand(sub);
|
|
309
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Install a plugin
|
|
421
|
+
*/
|
|
310
422
|
use(plugin) {
|
|
311
423
|
if (this.#plugins.has(plugin.name)) throw new Error(`Plugin '${plugin.name}' is already installed`);
|
|
312
424
|
const result = plugin.install(this);
|
|
313
425
|
this.#plugins.set(plugin.name, plugin);
|
|
314
426
|
return result || this;
|
|
315
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* Check if a plugin is installed
|
|
430
|
+
*/
|
|
316
431
|
hasPlugin(name) {
|
|
317
432
|
return this.#plugins.has(name);
|
|
318
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Get an installed plugin
|
|
436
|
+
*/
|
|
319
437
|
getPlugin(name) {
|
|
320
438
|
return this.#plugins.get(name);
|
|
321
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* List all installed plugins
|
|
442
|
+
*/
|
|
322
443
|
listPlugins() {
|
|
323
444
|
return Array.from(this.#plugins.keys());
|
|
324
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Add a flag
|
|
448
|
+
*/
|
|
325
449
|
addFlag(flag) {
|
|
326
450
|
this.#flagManager.addFlag(flag);
|
|
327
451
|
if ("prompt" in flag && typeof flag.prompt === "function") this.#promptManager.registerPromptableFlag(flag);
|
|
328
452
|
return this;
|
|
329
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
* Add multiple flags
|
|
456
|
+
*/
|
|
330
457
|
addFlags(flags) {
|
|
331
458
|
for (const flag of flags) this.addFlag(flag);
|
|
332
459
|
return this;
|
|
333
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* Check if a flag exists
|
|
463
|
+
*/
|
|
334
464
|
hasFlag(name) {
|
|
335
465
|
return this.#flagManager.hasFlag(name);
|
|
336
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Get a flag definition
|
|
469
|
+
*/
|
|
337
470
|
getFlagDefinition(name) {
|
|
338
471
|
return this.#flagManager.getFlag(name);
|
|
339
472
|
}
|
|
473
|
+
/**
|
|
474
|
+
* Get all flags
|
|
475
|
+
*/
|
|
340
476
|
get flags() {
|
|
341
477
|
return this.#flagManager.getAllFlags();
|
|
342
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* Get all flag names
|
|
481
|
+
*/
|
|
343
482
|
get flagNames() {
|
|
344
483
|
return this.#flagManager.getFlagNames();
|
|
345
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* Add a subcommand
|
|
487
|
+
*/
|
|
346
488
|
addSubCommand(subCommand) {
|
|
347
489
|
if (this.#subCommands.has(subCommand.name)) throw new Error(`Subcommand '${subCommand.name}' already exists`);
|
|
348
490
|
const subParser = subCommand.parser;
|
|
@@ -354,20 +496,35 @@ var ArgParser = class {
|
|
|
354
496
|
this.#subCommands.set(subCommand.name, subCommand);
|
|
355
497
|
return this;
|
|
356
498
|
}
|
|
499
|
+
/**
|
|
500
|
+
* Get a subcommand
|
|
501
|
+
*/
|
|
357
502
|
getSubCommand(name) {
|
|
358
503
|
return this.#subCommands.get(name);
|
|
359
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Get all subcommands
|
|
507
|
+
*/
|
|
360
508
|
getSubCommands() {
|
|
361
509
|
return new Map(this.#subCommands);
|
|
362
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Inherit flags to a sub-parser
|
|
513
|
+
*/
|
|
363
514
|
inheritFlagsToSubParser(subParser) {
|
|
364
515
|
const parentFlags = this.#flagManager.getAllFlags();
|
|
365
516
|
for (const flag of parentFlags) if (!subParser.hasFlag(flag.name)) subParser.#flagManager._setProcessedFlagForInheritance(flag);
|
|
366
517
|
}
|
|
518
|
+
/**
|
|
519
|
+
* Set the handler
|
|
520
|
+
*/
|
|
367
521
|
setHandler(handler) {
|
|
368
522
|
this.#handler = handler;
|
|
369
523
|
return this;
|
|
370
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* Get the handler
|
|
527
|
+
*/
|
|
371
528
|
getHandler() {
|
|
372
529
|
return this.#handler;
|
|
373
530
|
}
|
|
@@ -389,6 +546,9 @@ var ArgParser = class {
|
|
|
389
546
|
getPromptWhen() {
|
|
390
547
|
return this.#promptWhen;
|
|
391
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* Parse command line arguments
|
|
551
|
+
*/
|
|
392
552
|
async parse(processArgs, options = {}) {
|
|
393
553
|
const args = processArgs || process.argv.slice(2);
|
|
394
554
|
try {
|
|
@@ -421,6 +581,9 @@ var ArgParser = class {
|
|
|
421
581
|
throw error;
|
|
422
582
|
}
|
|
423
583
|
}
|
|
584
|
+
/**
|
|
585
|
+
* Parse flags only
|
|
586
|
+
*/
|
|
424
587
|
async parseFlags(args, _options = {}) {
|
|
425
588
|
const result = {};
|
|
426
589
|
const flags = this.#flagManager.getAllFlags();
|
|
@@ -454,6 +617,9 @@ var ArgParser = class {
|
|
|
454
617
|
if (missingFlags.length > 0) throw new ArgParserError(`Missing mandatory flags: ${missingFlags.join(", ")}`, [this.#appName]);
|
|
455
618
|
return result;
|
|
456
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* Parse a flag value based on type
|
|
622
|
+
*/
|
|
457
623
|
parseFlagValue(value, type) {
|
|
458
624
|
if (type === Boolean || type === "boolean") return /^(true|yes|1)$/i.test(value);
|
|
459
625
|
if (type === Number || type === "number") return Number(value);
|
|
@@ -461,6 +627,9 @@ var ArgParser = class {
|
|
|
461
627
|
if (typeof type === "function") return type(value);
|
|
462
628
|
return value;
|
|
463
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* Find the command chain for subcommands
|
|
632
|
+
*/
|
|
464
633
|
findCommandChain(args) {
|
|
465
634
|
let currentParser = this;
|
|
466
635
|
const commandChain = [];
|
|
@@ -479,6 +648,9 @@ var ArgParser = class {
|
|
|
479
648
|
remainingArgs
|
|
480
649
|
};
|
|
481
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* Detect and strip system flags
|
|
653
|
+
*/
|
|
482
654
|
detectAndStripSystemFlags(args) {
|
|
483
655
|
const systemArgs = {};
|
|
484
656
|
const filteredArgs = [];
|
|
@@ -501,6 +673,9 @@ var ArgParser = class {
|
|
|
501
673
|
filteredArgs
|
|
502
674
|
};
|
|
503
675
|
}
|
|
676
|
+
/**
|
|
677
|
+
* Handle exit
|
|
678
|
+
*/
|
|
504
679
|
handleExit(exitCode, message, type) {
|
|
505
680
|
const result = {
|
|
506
681
|
success: exitCode === 0,
|
|
@@ -512,6 +687,9 @@ var ArgParser = class {
|
|
|
512
687
|
if (this.#autoExit && typeof process !== "undefined" && process.exit) process.exit(exitCode);
|
|
513
688
|
return result;
|
|
514
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Generate help text
|
|
692
|
+
*/
|
|
515
693
|
helpText() {
|
|
516
694
|
const lines = [];
|
|
517
695
|
lines.push(chalk.bold(this.#appName));
|
|
@@ -540,11 +718,22 @@ var ArgParser = class {
|
|
|
540
718
|
return lines.join("\n");
|
|
541
719
|
}
|
|
542
720
|
};
|
|
721
|
+
//#endregion
|
|
722
|
+
//#region src/plugin/types.ts
|
|
723
|
+
/**
|
|
724
|
+
* Plugin registry for managing installed plugins
|
|
725
|
+
*
|
|
726
|
+
* This class tracks which plugins are installed on a parser instance
|
|
727
|
+
* and provides methods for introspection.
|
|
728
|
+
*/
|
|
543
729
|
var PluginRegistry = class {
|
|
544
730
|
constructor() {
|
|
545
731
|
this.plugins = /* @__PURE__ */ new Map();
|
|
546
732
|
this.metadata = /* @__PURE__ */ new Map();
|
|
547
733
|
}
|
|
734
|
+
/**
|
|
735
|
+
* Register a plugin in the registry
|
|
736
|
+
*/
|
|
548
737
|
register(plugin, metadata) {
|
|
549
738
|
if (this.plugins.has(plugin.name)) {
|
|
550
739
|
console.warn(`[ArgParser] Plugin '${plugin.name}' is already registered`);
|
|
@@ -553,36 +742,74 @@ var PluginRegistry = class {
|
|
|
553
742
|
this.plugins.set(plugin.name, plugin);
|
|
554
743
|
if (metadata) this.metadata.set(plugin.name, metadata);
|
|
555
744
|
}
|
|
745
|
+
/**
|
|
746
|
+
* Get a registered plugin by name
|
|
747
|
+
*/
|
|
556
748
|
get(name) {
|
|
557
749
|
return this.plugins.get(name);
|
|
558
750
|
}
|
|
751
|
+
/**
|
|
752
|
+
* Check if a plugin is registered
|
|
753
|
+
*/
|
|
559
754
|
has(name) {
|
|
560
755
|
return this.plugins.has(name);
|
|
561
756
|
}
|
|
757
|
+
/**
|
|
758
|
+
* List all registered plugin names
|
|
759
|
+
*/
|
|
562
760
|
list() {
|
|
563
761
|
return Array.from(this.plugins.keys());
|
|
564
762
|
}
|
|
763
|
+
/**
|
|
764
|
+
* Get metadata for a plugin
|
|
765
|
+
*/
|
|
565
766
|
getMetadata(name) {
|
|
566
767
|
return this.metadata.get(name);
|
|
567
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* Unregister a plugin
|
|
771
|
+
*/
|
|
568
772
|
unregister(name) {
|
|
569
773
|
const plugin = this.plugins.get(name);
|
|
570
774
|
if (plugin?.destroy) plugin.destroy();
|
|
571
775
|
this.metadata.delete(name);
|
|
572
776
|
return this.plugins.delete(name);
|
|
573
777
|
}
|
|
778
|
+
/**
|
|
779
|
+
* Clear all registered plugins
|
|
780
|
+
*/
|
|
574
781
|
clear() {
|
|
575
782
|
for (const [, plugin] of this.plugins) if (plugin.destroy) plugin.destroy();
|
|
576
783
|
this.plugins.clear();
|
|
577
784
|
this.metadata.clear();
|
|
578
785
|
}
|
|
579
786
|
};
|
|
580
|
-
|
|
787
|
+
/**
|
|
788
|
+
* Global plugin registry for system-wide plugin management
|
|
789
|
+
*/
|
|
790
|
+
var globalPluginRegistry = new PluginRegistry();
|
|
791
|
+
/**
|
|
792
|
+
* Decorator for plugin methods that should be exposed on the parser
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* class MyPlugin implements IArgParserPlugin {
|
|
797
|
+
* name = 'my-plugin';
|
|
798
|
+
*
|
|
799
|
+
@expose()
|
|
800
|
+
* myMethod(parser: ArgParserBase, ...args: any[]) {
|
|
801
|
+
* // Implementation
|
|
802
|
+
* }
|
|
803
|
+
* }
|
|
804
|
+
* ```
|
|
805
|
+
*/
|
|
581
806
|
function expose(_target, propertyKey, descriptor) {
|
|
582
807
|
descriptor.value._isExposed = true;
|
|
583
808
|
descriptor.value._exposedName = propertyKey;
|
|
584
809
|
return descriptor;
|
|
585
810
|
}
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/config/plugins/index.ts
|
|
586
813
|
var ConfigPlugin = class {};
|
|
587
814
|
var JsonConfigPlugin = class extends ConfigPlugin {
|
|
588
815
|
constructor(..._args) {
|
|
@@ -623,7 +850,7 @@ var ConfigPluginRegistry = class {
|
|
|
623
850
|
for (const plugin of this.plugins.values()) if (plugin.canLoad(source)) return plugin;
|
|
624
851
|
}
|
|
625
852
|
};
|
|
626
|
-
|
|
853
|
+
var globalConfigPluginRegistry = new ConfigPluginRegistry();
|
|
627
854
|
globalConfigPluginRegistry.register(new JsonConfigPlugin());
|
|
628
855
|
globalConfigPluginRegistry.register(new EnvConfigPlugin());
|
|
629
856
|
async function enableOptionalConfigPlugins() {}
|
|
@@ -631,7 +858,15 @@ async function enableOptionalConfigPluginsAsync() {
|
|
|
631
858
|
await enableOptionalConfigPlugins();
|
|
632
859
|
}
|
|
633
860
|
function enableConfigPlugins() {}
|
|
634
|
-
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/utils/debug-utils.ts
|
|
863
|
+
/**
|
|
864
|
+
* Debug utilities for ArgParser
|
|
865
|
+
*/
|
|
866
|
+
/**
|
|
867
|
+
* Debug logger that only logs when DEBUG environment variable is set
|
|
868
|
+
*/
|
|
869
|
+
var debug = {
|
|
635
870
|
log: (...args) => {
|
|
636
871
|
if (process.env["DEBUG"] || process.env["ARG_PARSER_DEBUG"]) console.log("[ArgParser Debug]", ...args);
|
|
637
872
|
},
|
|
@@ -642,10 +877,25 @@ const debug = {
|
|
|
642
877
|
if (process.env["DEBUG"] || process.env["ARG_PARSER_DEBUG"]) console.warn("[ArgParser Debug]", ...args);
|
|
643
878
|
}
|
|
644
879
|
};
|
|
880
|
+
//#endregion
|
|
881
|
+
//#region src/core/log-path-utils.ts
|
|
882
|
+
/**
|
|
883
|
+
* Log path utilities for ArgParser
|
|
884
|
+
*
|
|
885
|
+
* Provides flexible path resolution for log files, supporting
|
|
886
|
+
* relative paths (to entry point or cwd), absolute paths, and
|
|
887
|
+
* configuration objects.
|
|
888
|
+
*/
|
|
889
|
+
/**
|
|
890
|
+
* Detect the entry point of the application
|
|
891
|
+
*/
|
|
645
892
|
function detectEntryPoint() {
|
|
646
893
|
if (process.argv[1]) return path.resolve(process.argv[1]);
|
|
647
894
|
return process.cwd();
|
|
648
895
|
}
|
|
896
|
+
/**
|
|
897
|
+
* Get entry point from import.meta.url
|
|
898
|
+
*/
|
|
649
899
|
function getEntryPointFromImportMeta(importMetaUrl) {
|
|
650
900
|
try {
|
|
651
901
|
return new URL(importMetaUrl).pathname;
|
|
@@ -653,18 +903,21 @@ function getEntryPointFromImportMeta(importMetaUrl) {
|
|
|
653
903
|
return process.cwd();
|
|
654
904
|
}
|
|
655
905
|
}
|
|
906
|
+
/**
|
|
907
|
+
* Resolve a log path to an absolute path
|
|
908
|
+
*/
|
|
656
909
|
function resolveLogPath(logPath) {
|
|
657
910
|
if (typeof logPath === "string") {
|
|
658
911
|
if (logPath.startsWith("cwd:")) return path.resolve(process.cwd(), logPath.slice(4));
|
|
659
912
|
if (logPath.startsWith("entry:")) {
|
|
660
|
-
const entryPoint
|
|
661
|
-
const entryDir
|
|
662
|
-
return path.resolve(entryDir
|
|
913
|
+
const entryPoint = detectEntryPoint();
|
|
914
|
+
const entryDir = path.dirname(entryPoint);
|
|
915
|
+
return path.resolve(entryDir, logPath.slice(6));
|
|
663
916
|
}
|
|
664
917
|
if (path.isAbsolute(logPath)) return logPath;
|
|
665
|
-
const entryPoint
|
|
666
|
-
const entryDir
|
|
667
|
-
return path.resolve(entryDir
|
|
918
|
+
const entryPoint = detectEntryPoint();
|
|
919
|
+
const entryDir = path.dirname(entryPoint);
|
|
920
|
+
return path.resolve(entryDir, logPath);
|
|
668
921
|
}
|
|
669
922
|
const { path: pathStr, relativeTo = "entry", basePath } = logPath;
|
|
670
923
|
if (relativeTo === "absolute") return pathStr;
|
|
@@ -673,20 +926,33 @@ function resolveLogPath(logPath) {
|
|
|
673
926
|
const entryDir = path.dirname(entryPoint);
|
|
674
927
|
return path.resolve(entryDir, pathStr);
|
|
675
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* Create a path relative to the entry point
|
|
931
|
+
*/
|
|
676
932
|
function entryRelative(subPath) {
|
|
677
933
|
const entryPoint = detectEntryPoint();
|
|
678
934
|
const entryDir = path.dirname(entryPoint);
|
|
679
935
|
return path.resolve(entryDir, subPath);
|
|
680
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* Create a path relative to the current working directory
|
|
939
|
+
*/
|
|
681
940
|
function cwdRelative(subPath) {
|
|
682
941
|
return path.resolve(process.cwd(), subPath);
|
|
683
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* Create an absolute path
|
|
945
|
+
*/
|
|
684
946
|
function absolutePath(pathStr) {
|
|
685
947
|
return path.resolve(pathStr);
|
|
686
948
|
}
|
|
949
|
+
/**
|
|
950
|
+
* Legacy cwd-relative path (for backward compatibility)
|
|
951
|
+
*/
|
|
687
952
|
function legacyCwdPath(subPath) {
|
|
688
953
|
return cwdRelative(subPath);
|
|
689
954
|
}
|
|
955
|
+
//#endregion
|
|
690
956
|
export { ArgParser, ArgParserError, ConfigPlugin, ConfigPluginRegistry, EnvConfigPlugin, FlagInheritance, FlagManager, JsonConfigPlugin, OutputSchemaPatterns, PluginRegistry, PromptManager, SimpleChalk, absolutePath, createOutputSchema, cwdRelative, debug, detectEntryPoint, enableConfigPlugins, enableOptionalConfigPlugins, enableOptionalConfigPluginsAsync, entryRelative, expose, getEntryPointFromImportMeta, getJsonSchemaTypeFromFlag, globalConfigPluginRegistry, globalPluginRegistry, legacyCwdPath, resolveLogPath, zodDxtOptionsSchema, zodFlagSchema };
|
|
691
957
|
|
|
692
958
|
//# sourceMappingURL=index.mjs.map
|