@alcyone-labs/arg-parser 2.13.5 → 2.14.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/dist/core/ArgParserBase.d.ts +55 -1
- package/dist/core/ArgParserBase.d.ts.map +1 -1
- package/dist/core/FlagManager.d.ts +160 -3
- package/dist/core/FlagManager.d.ts.map +1 -1
- package/dist/core/PromptManager.d.ts +102 -0
- package/dist/core/PromptManager.d.ts.map +1 -0
- package/dist/core/types.d.ts +224 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.cjs +2312 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.min.mjs +5140 -3558
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +1612 -124
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -10
|
@@ -2,7 +2,7 @@ import { type Logger } from "@alcyone-labs/simple-mcp-logger";
|
|
|
2
2
|
import { McpNotificationsManager, type McpChangeType } from "../mcp/mcp-notifications.js";
|
|
3
3
|
import { McpPromptsManager, type McpPromptConfig } from "../mcp/mcp-prompts.js";
|
|
4
4
|
import { McpResourcesManager, type McpResourceConfig } from "../mcp/mcp-resources.js";
|
|
5
|
-
import type { IArgParser, IFlag, IHandlerContext, ISubCommand, ParseResult, ProcessedFlag,
|
|
5
|
+
import type { IArgParser, IFlag, IHandlerContext, IPromptableFlag, ISubCommand, ParseResult, ProcessedFlag, PromptWhen, TParsedArgs, TFlagInheritance } from "./types";
|
|
6
6
|
export declare class ArgParserError extends Error {
|
|
7
7
|
cmdChain: string[];
|
|
8
8
|
commandChain: string[];
|
|
@@ -86,6 +86,33 @@ export interface IArgParserParams<THandlerReturn = any> {
|
|
|
86
86
|
* If not provided, a default one will be created.
|
|
87
87
|
*/
|
|
88
88
|
logger?: Logger;
|
|
89
|
+
/**
|
|
90
|
+
* When to trigger interactive prompts for this command.
|
|
91
|
+
* - `"interactive-flag"` (default): Prompts shown only when `--interactive` or `-i` flag is present
|
|
92
|
+
* - `"missing"`: Prompts shown when any promptable flag is missing a value
|
|
93
|
+
* - `"always"`: Always show prompts (overrides CLI args for promptable flags)
|
|
94
|
+
*
|
|
95
|
+
* @default "interactive-flag"
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const cli = new ArgParser({
|
|
100
|
+
* appName: "my-cli",
|
|
101
|
+
* promptWhen: "interactive-flag",
|
|
102
|
+
* handler: async (ctx) => {
|
|
103
|
+
* if (ctx.isInteractive) {
|
|
104
|
+
* console.log("Interactive mode:", ctx.promptAnswers);
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
promptWhen?: import("./types").PromptWhen;
|
|
111
|
+
/**
|
|
112
|
+
* Called when user cancels (Ctrl+C) during interactive prompts.
|
|
113
|
+
* If not provided, exits gracefully with code 0.
|
|
114
|
+
*/
|
|
115
|
+
onCancel?: (ctx: import("./types").IHandlerContext) => void | Promise<void>;
|
|
89
116
|
}
|
|
90
117
|
export interface IParseOptions {
|
|
91
118
|
/**
|
|
@@ -158,9 +185,36 @@ export declare class ArgParserBase<THandlerReturn = any> implements IArgParser<T
|
|
|
158
185
|
private _handleExit;
|
|
159
186
|
getHandler(): ((ctx: IHandlerContext) => void) | undefined;
|
|
160
187
|
getSubCommands(): Map<string, ISubCommand>;
|
|
188
|
+
/**
|
|
189
|
+
* Sets the promptWhen setting for this parser.
|
|
190
|
+
* Used internally to propagate promptWhen from parent to sub-parser.
|
|
191
|
+
* @param promptWhen - The promptWhen value
|
|
192
|
+
*/
|
|
193
|
+
setPromptWhen(promptWhen: PromptWhen): this;
|
|
194
|
+
/**
|
|
195
|
+
* Sets the onCancel callback for this parser.
|
|
196
|
+
* Used internally to propagate onCancel from parent to sub-parser.
|
|
197
|
+
* @param onCancel - The onCancel callback
|
|
198
|
+
*/
|
|
199
|
+
setOnCancel(onCancel: (ctx: IHandlerContext) => void | Promise<void>): this;
|
|
161
200
|
private _addToOutput;
|
|
162
201
|
addFlags(flags: readonly IFlag[]): this;
|
|
163
202
|
addFlag(flag: IFlag): this;
|
|
203
|
+
/**
|
|
204
|
+
* Collects all flags that have interactive prompt configuration.
|
|
205
|
+
* These flags can participate in interactive mode.
|
|
206
|
+
*
|
|
207
|
+
* @returns Array of promptable flags with their names
|
|
208
|
+
*/
|
|
209
|
+
getPromptableFlags(): Array<{
|
|
210
|
+
flag: IPromptableFlag;
|
|
211
|
+
name: string;
|
|
212
|
+
}>;
|
|
213
|
+
/**
|
|
214
|
+
* Gets the promptWhen setting for this parser.
|
|
215
|
+
* @returns The promptWhen value
|
|
216
|
+
*/
|
|
217
|
+
getPromptWhen(): PromptWhen;
|
|
164
218
|
addSubCommand(subCommandConfig: ISubCommand): this;
|
|
165
219
|
/**
|
|
166
220
|
* Sets the handler function for this specific parser instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArgParserBase.d.ts","sourceRoot":"","sources":["../../src/core/ArgParserBase.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAG/E,OAAO,EAAE,uBAAuB,EAAE,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"ArgParserBase.d.ts","sourceRoot":"","sources":["../../src/core/ArgParserBase.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAG/E,OAAO,EAAE,uBAAuB,EAAE,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,iBA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GACtF,IAAI;IAKP;;OAEG;IACH,0BAA0B,IAAI,uBAAuB;IAIrD;;OAEG;IACH,sBAAsB,IAAI,mBAAmB;IAI7C;;OAEG;IACH,oBAAoB,IAAI,iBAAiB;CA8d1C;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAU,KAAK,eAAe,kBAEzD,CAAC"}
|
|
@@ -1,17 +1,174 @@
|
|
|
1
1
|
import type { IFlag, ProcessedFlag } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Options for FlagManager configuration.
|
|
4
|
+
*/
|
|
5
|
+
export interface FlagManagerOptions {
|
|
6
|
+
/** Whether to throw an error when a flag with a duplicate name is added. If false, a warning is logged and the duplicate is skipped. @default false */
|
|
7
|
+
throwForDuplicateFlags?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to detect and report collisions between flag option strings (e.g., two flags both using `-f` or `--file`).
|
|
10
|
+
* When enabled, adding a flag with an option string that conflicts with an existing flag will trigger a warning or error.
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
detectOptionCollisions?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to throw an error when flag option collisions are detected.
|
|
16
|
+
* If false, a warning is logged but the flag is still added.
|
|
17
|
+
* Only applies when detectOptionCollisions is true.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
throwForOptionCollisions?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Represents a collision between flag option strings.
|
|
24
|
+
*/
|
|
25
|
+
export interface FlagOptionCollision {
|
|
26
|
+
/** The option string that collides (e.g., "-f" or "--file") */
|
|
27
|
+
option: string;
|
|
28
|
+
/** The name of the flag that was already registered with this option */
|
|
29
|
+
existingFlagName: string;
|
|
30
|
+
/** The name of the flag being added that causes the collision */
|
|
31
|
+
newFlagName: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Manages flag definitions and detects collisions between flag names and option strings.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const manager = new FlagManager({
|
|
39
|
+
* throwForDuplicateFlags: true,
|
|
40
|
+
* detectOptionCollisions: true,
|
|
41
|
+
* throwForOptionCollisions: true
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* manager.addFlag({
|
|
45
|
+
* name: "file",
|
|
46
|
+
* options: ["-f", "--file"],
|
|
47
|
+
* type: "string"
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // This will throw because "-f" is already used:
|
|
51
|
+
* manager.addFlag({
|
|
52
|
+
* name: "force",
|
|
53
|
+
* options: ["-f", "--force"],
|
|
54
|
+
* type: "boolean"
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
2
58
|
export declare class FlagManager {
|
|
3
59
|
#private;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new FlagManager instance.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Configuration options for the manager
|
|
64
|
+
* @param initialFlags - Optional array of flags to add immediately
|
|
65
|
+
*/
|
|
66
|
+
constructor(options?: FlagManagerOptions, initialFlags?: readonly IFlag[]);
|
|
67
|
+
/**
|
|
68
|
+
* Converts a raw IFlag to a ProcessedFlag with resolved types.
|
|
69
|
+
*
|
|
70
|
+
* @param flag - The flag definition to process
|
|
71
|
+
* @returns The processed flag with resolved types
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
7
74
|
static _safeFlag(flag: IFlag): ProcessedFlag;
|
|
75
|
+
/**
|
|
76
|
+
* Adds a flag to the manager.
|
|
77
|
+
*
|
|
78
|
+
* Detects name collisions (if throwForDuplicateFlags is true) and
|
|
79
|
+
* option string collisions (if detectOptionCollisions is true).
|
|
80
|
+
*
|
|
81
|
+
* @param flag - The flag definition to add
|
|
82
|
+
* @returns The FlagManager instance for chaining
|
|
83
|
+
* @throws {Error} If throwForDuplicateFlags is true and a flag with the same name exists
|
|
84
|
+
* @throws {Error} If throwForOptionCollisions is true and option collisions are detected
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* manager.addFlag({
|
|
89
|
+
* name: "verbose",
|
|
90
|
+
* options: ["-v", "--verbose"],
|
|
91
|
+
* type: "boolean",
|
|
92
|
+
* description: "Enable verbose output"
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
8
96
|
addFlag(flag: IFlag): this;
|
|
97
|
+
/**
|
|
98
|
+
* Sets a processed flag for inheritance from a parent parser.
|
|
99
|
+
* This bypasses collision detection since inherited flags are intentional.
|
|
100
|
+
*
|
|
101
|
+
* @param processedFlag - The processed flag to add
|
|
102
|
+
* @returns The FlagManager instance for chaining
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
9
105
|
_setProcessedFlagForInheritance(processedFlag: ProcessedFlag): this;
|
|
106
|
+
/**
|
|
107
|
+
* Adds multiple flags to the manager.
|
|
108
|
+
*
|
|
109
|
+
* @param flags - Array of flag definitions to add
|
|
110
|
+
* @returns The FlagManager instance for chaining
|
|
111
|
+
*/
|
|
10
112
|
addFlags(flags: readonly IFlag[]): this;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if a flag with the given name exists.
|
|
115
|
+
*
|
|
116
|
+
* @param name - The flag name to check
|
|
117
|
+
* @returns True if the flag exists, false otherwise
|
|
118
|
+
*/
|
|
11
119
|
hasFlag(name: string): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Removes a flag by name.
|
|
122
|
+
*
|
|
123
|
+
* @param name - The name of the flag to remove
|
|
124
|
+
* @returns True if the flag was removed, false if it didn't exist
|
|
125
|
+
*/
|
|
12
126
|
removeFlag(name: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Gets a flag by name.
|
|
129
|
+
*
|
|
130
|
+
* @param name - The name of the flag to retrieve
|
|
131
|
+
* @returns The flag definition, or undefined if not found
|
|
132
|
+
*/
|
|
13
133
|
getFlag(name: string): ProcessedFlag | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* Gets all registered flags.
|
|
136
|
+
*
|
|
137
|
+
* @returns An array of all registered flags
|
|
138
|
+
*/
|
|
14
139
|
get flags(): ProcessedFlag[];
|
|
140
|
+
/**
|
|
141
|
+
* Gets all registered flag names.
|
|
142
|
+
*
|
|
143
|
+
* @returns An array of all flag names
|
|
144
|
+
*/
|
|
15
145
|
get flagNames(): string[];
|
|
146
|
+
/**
|
|
147
|
+
* Gets all registered option strings and their associated flag names.
|
|
148
|
+
*
|
|
149
|
+
* @returns A map of option strings to flag names
|
|
150
|
+
*/
|
|
151
|
+
get optionMappings(): ReadonlyMap<string, string>;
|
|
152
|
+
/**
|
|
153
|
+
* Gets all collisions between the given flag and existing flags.
|
|
154
|
+
* Useful for pre-validation before adding a flag.
|
|
155
|
+
*
|
|
156
|
+
* @param flag - The flag to check for collisions
|
|
157
|
+
* @returns An array of detected collisions, empty if none
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const collisions = manager.getCollisionsForFlag({
|
|
162
|
+
* name: "force",
|
|
163
|
+
* options: ["-f", "--force"],
|
|
164
|
+
* type: "boolean"
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* if (collisions.length > 0) {
|
|
168
|
+
* console.log("Collisions detected:", collisions);
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
getCollisionsForFlag(flag: IFlag): FlagOptionCollision[];
|
|
16
173
|
}
|
|
17
174
|
//# sourceMappingURL=FlagManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlagManager.d.ts","sourceRoot":"","sources":["../../src/core/FlagManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEpD,
|
|
1
|
+
{"version":3,"file":"FlagManager.d.ts","sourceRoot":"","sources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AS,IAAI,MAAM,EAAE,CAExB;IAED;;;;OAIG;IACH,IAAI,cAAc,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhD;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,oBAAoB,CAAC,IAAI,EAAE,KAAK,GAAG,mBAAmB,EAAE;CAIzD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { IHandlerContext, IPromptableFlag, PromptWhen } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating a PromptManager instance.
|
|
4
|
+
*/
|
|
5
|
+
export interface PromptManagerOptions {
|
|
6
|
+
/** The current handler context, used for passing to prompt functions */
|
|
7
|
+
context: IHandlerContext;
|
|
8
|
+
/** Called when user cancels (Ctrl+C) during prompts */
|
|
9
|
+
onCancel?: (ctx: IHandlerContext) => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Result of executing interactive prompts.
|
|
13
|
+
*/
|
|
14
|
+
export interface PromptResult {
|
|
15
|
+
/** Whether the prompts were completed successfully */
|
|
16
|
+
success: boolean;
|
|
17
|
+
/** The collected answers (flag name -> value) */
|
|
18
|
+
answers: Record<string, any>;
|
|
19
|
+
/** Whether the user cancelled */
|
|
20
|
+
cancelled: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Manages interactive prompts using @clack/prompts.
|
|
24
|
+
*
|
|
25
|
+
* This class handles:
|
|
26
|
+
* - Collecting promptable flags and sorting them by sequence
|
|
27
|
+
* - Executing prompts in order with @clack/prompts
|
|
28
|
+
* - Validation and re-prompt loops
|
|
29
|
+
* - User cancellation (Ctrl+C)
|
|
30
|
+
* - TTY detection
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const promptManager = new PromptManager({
|
|
35
|
+
* context: handlerContext,
|
|
36
|
+
* onCancel: () => console.log("Cancelled")
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* const result = await promptManager.executePrompts([
|
|
40
|
+
* { flag: envFlag, name: "environment" },
|
|
41
|
+
* { flag: versionFlag, name: "version" }
|
|
42
|
+
* ]);
|
|
43
|
+
*
|
|
44
|
+
* if (result.success) {
|
|
45
|
+
* console.log("Answers:", result.answers);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class PromptManager {
|
|
50
|
+
#private;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new PromptManager instance.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Configuration options
|
|
55
|
+
*/
|
|
56
|
+
constructor(options: PromptManagerOptions);
|
|
57
|
+
/**
|
|
58
|
+
* Checks if the current environment supports interactive prompts.
|
|
59
|
+
* Returns false in non-TTY environments (CI, pipes, etc.).
|
|
60
|
+
*/
|
|
61
|
+
static isInteractiveEnvironment(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Determines if interactive mode should be triggered based on promptWhen condition.
|
|
64
|
+
*
|
|
65
|
+
* @param promptWhen - The condition to check
|
|
66
|
+
* @param flags - The promptable flags to check
|
|
67
|
+
* @param args - The current parsed args
|
|
68
|
+
* @returns True if interactive mode should be triggered
|
|
69
|
+
*/
|
|
70
|
+
static shouldTriggerInteractive(promptWhen: PromptWhen, flags: Array<{
|
|
71
|
+
flag: IPromptableFlag;
|
|
72
|
+
name: string;
|
|
73
|
+
}>, args: Record<string, any>): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Sorts flags by their prompt sequence.
|
|
76
|
+
* Falls back to array order if promptSequence is not specified.
|
|
77
|
+
* Ties are broken by array order.
|
|
78
|
+
*
|
|
79
|
+
* @param flags - Array of flags to sort
|
|
80
|
+
* @returns Sorted array of flags
|
|
81
|
+
*/
|
|
82
|
+
static sortFlagsBySequence(flags: Array<{
|
|
83
|
+
flag: IPromptableFlag;
|
|
84
|
+
name: string;
|
|
85
|
+
index: number;
|
|
86
|
+
}>): Array<{
|
|
87
|
+
flag: IPromptableFlag;
|
|
88
|
+
name: string;
|
|
89
|
+
index: number;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Executes all prompts in sequence.
|
|
93
|
+
*
|
|
94
|
+
* @param flags - Array of promptable flags with their names
|
|
95
|
+
* @returns The result of the prompt execution
|
|
96
|
+
*/
|
|
97
|
+
executePrompts(flags: Array<{
|
|
98
|
+
flag: IPromptableFlag;
|
|
99
|
+
name: string;
|
|
100
|
+
}>): Promise<PromptResult>;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=PromptManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptManager.d.ts","sourceRoot":"","sources":["../../src/core/PromptManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAqB,UAAU,EAAE,MAAM,SAAS,CAAC;AAE/F;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wEAAwE;IACxE,OAAO,EAAE,eAAe,CAAC;IACzB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,iCAAiC;IACjC,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,aAAa;;IAIxB;;;;OAIG;gBACS,OAAO,EAAE,oBAAoB;IAKzC;;;OAGG;IACH,MAAM,CAAC,wBAAwB,IAAI,OAAO;IAQ1C;;;;;;;OAOG;IACH,MAAM,CAAC,wBAAwB,CAC7B,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,EACrD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACxB,OAAO;IAsBV;;;;;;;OAOG;IACH,MAAM,CAAC,mBAAmB,CACxB,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GACnE,KAAK,CAAC;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAchE;;;;;OAKG;IACG,cAAc,CAClB,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,GACpD,OAAO,CAAC,YAAY,CAAC;CA0KzB"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -42,6 +42,9 @@ export interface IArgParser<THandlerReturn = any> {
|
|
|
42
42
|
removeMcpPrompt(name: string): this;
|
|
43
43
|
getMcpPrompts(): any[];
|
|
44
44
|
getMcpServerConfig?(): any;
|
|
45
|
+
setPromptWhen?(promptWhen: PromptWhen): this;
|
|
46
|
+
setOnCancel?(onCancel: (ctx: IHandlerContext) => void | Promise<void>): this;
|
|
47
|
+
getPromptWhen?(): PromptWhen;
|
|
45
48
|
}
|
|
46
49
|
/**
|
|
47
50
|
* Defines the behavior for flag inheritance in sub-commands.
|
|
@@ -115,6 +118,8 @@ export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
|
|
|
115
118
|
dynamicRegister: z.ZodOptional<z.ZodCustom<DynamicRegisterFn, DynamicRegisterFn>>;
|
|
116
119
|
setWorkingDirectory: z.ZodOptional<z.ZodBoolean>;
|
|
117
120
|
positional: z.ZodOptional<z.ZodNumber>;
|
|
121
|
+
prompt: z.ZodOptional<z.ZodCustom<(ctx: any) => any, (ctx: any) => any>>;
|
|
122
|
+
promptSequence: z.ZodOptional<z.ZodNumber>;
|
|
118
123
|
}, z.core.$strip>, z.ZodTransform<{
|
|
119
124
|
[key: string]: any;
|
|
120
125
|
}, {
|
|
@@ -144,6 +149,8 @@ export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
|
|
|
144
149
|
dynamicRegister?: DynamicRegisterFn | undefined;
|
|
145
150
|
setWorkingDirectory?: boolean | undefined;
|
|
146
151
|
positional?: number | undefined;
|
|
152
|
+
prompt?: ((ctx: any) => any) | undefined;
|
|
153
|
+
promptSequence?: number | undefined;
|
|
147
154
|
}>>;
|
|
148
155
|
/**
|
|
149
156
|
* The raw input type for defining a flag, before Zod processing (aliases, defaults).
|
|
@@ -296,6 +303,163 @@ export type TParsedArgs<TFlags extends readonly ProcessedFlag[]> = {
|
|
|
296
303
|
name: K;
|
|
297
304
|
}>>;
|
|
298
305
|
};
|
|
306
|
+
/**
|
|
307
|
+
* System flags detected during parsing.
|
|
308
|
+
* These flags are processed by ArgParser internally and made available to handlers
|
|
309
|
+
* for inspection and debugging purposes.
|
|
310
|
+
*/
|
|
311
|
+
export interface ISystemArgs {
|
|
312
|
+
/** Whether --s-debug flag was present (enables debug output) */
|
|
313
|
+
debug?: boolean;
|
|
314
|
+
/** Whether --s-debug-print flag was present (prints config and exits) */
|
|
315
|
+
debugPrint?: boolean;
|
|
316
|
+
/** Whether --s-enable-fuzzy flag was present (enables fuzzy testing mode) */
|
|
317
|
+
enableFuzzy?: boolean;
|
|
318
|
+
/** Path provided with --s-with-env flag (loads env config from file), or true if no path */
|
|
319
|
+
withEnv?: string | true;
|
|
320
|
+
/** Whether --s-save-to-env flag was present (saves config to env file) */
|
|
321
|
+
saveToEnv?: boolean;
|
|
322
|
+
/** Output path for --s-build-dxt flag (generates DXT package), or true if no path */
|
|
323
|
+
buildDxt?: string | true;
|
|
324
|
+
/** Whether --s-mcp-serve flag was present (starts MCP server) */
|
|
325
|
+
mcpServe?: boolean;
|
|
326
|
+
/** Transport type from --s-mcp-transport flag */
|
|
327
|
+
mcpTransport?: string;
|
|
328
|
+
/** Port from --s-mcp-port flag */
|
|
329
|
+
mcpPort?: number;
|
|
330
|
+
/** Host from --s-mcp-host flag */
|
|
331
|
+
mcpHost?: string;
|
|
332
|
+
/** Path from --s-mcp-path flag */
|
|
333
|
+
mcpPath?: string;
|
|
334
|
+
/** Transports config from --s-mcp-transports flag */
|
|
335
|
+
mcpTransports?: string;
|
|
336
|
+
/** Log path from --s-mcp-log-path flag */
|
|
337
|
+
mcpLogPath?: string;
|
|
338
|
+
/** CORS config from --s-mcp-cors flag */
|
|
339
|
+
mcpCors?: any;
|
|
340
|
+
/** Auth config from --s-mcp-auth flag */
|
|
341
|
+
mcpAuth?: any;
|
|
342
|
+
/** Raw system flags that were detected but not explicitly typed */
|
|
343
|
+
[key: string]: any;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Types of interactive prompts supported by @clack/prompts integration.
|
|
347
|
+
*/
|
|
348
|
+
export type PromptType = "text" | "password" | "confirm" | "select" | "multiselect";
|
|
349
|
+
/**
|
|
350
|
+
* Configuration for a single interactive prompt field.
|
|
351
|
+
* Used to define the appearance and behavior of a prompt.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* {
|
|
356
|
+
* type: "select",
|
|
357
|
+
* message: "Select environment:",
|
|
358
|
+
* options: [
|
|
359
|
+
* { label: "Staging", value: "staging", hint: "Safe for testing" },
|
|
360
|
+
* { label: "Production", value: "production", hint: "Careful!" }
|
|
361
|
+
* ],
|
|
362
|
+
* validate: (val) => val !== "production" || confirm("Are you sure?")
|
|
363
|
+
* }
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
export interface PromptFieldConfig {
|
|
367
|
+
/** Type of prompt to display */
|
|
368
|
+
type: PromptType;
|
|
369
|
+
/** Message shown to the user */
|
|
370
|
+
message: string;
|
|
371
|
+
/** Placeholder text (for text/password types) */
|
|
372
|
+
placeholder?: string;
|
|
373
|
+
/** Initial/default value */
|
|
374
|
+
initial?: any;
|
|
375
|
+
/**
|
|
376
|
+
* Validation function.
|
|
377
|
+
* Return true for valid, string for error message.
|
|
378
|
+
* Can be async.
|
|
379
|
+
*/
|
|
380
|
+
validate?: (value: any, ctx: IHandlerContext) => boolean | string | Promise<boolean | string>;
|
|
381
|
+
/**
|
|
382
|
+
* Options for select/multiselect.
|
|
383
|
+
* Can be simple strings or label/value objects.
|
|
384
|
+
*/
|
|
385
|
+
options?: Array<string | {
|
|
386
|
+
label: string;
|
|
387
|
+
value: any;
|
|
388
|
+
hint?: string;
|
|
389
|
+
}>;
|
|
390
|
+
/** Maximum items to show before scrolling (select/multiselect) */
|
|
391
|
+
maxItems?: number;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* When to trigger interactive prompts for a command.
|
|
395
|
+
* - `"interactive-flag"`: Prompts shown only when `--interactive` or `-i` flag is present (default)
|
|
396
|
+
* - `"missing"`: Prompts shown when any promptable flag is missing a value
|
|
397
|
+
* - `"always"`: Always show prompts (overrides CLI args for promptable flags)
|
|
398
|
+
*/
|
|
399
|
+
export type PromptWhen = "interactive-flag" | "missing" | "always";
|
|
400
|
+
/**
|
|
401
|
+
* Extended flag with interactive prompt capability.
|
|
402
|
+
* Flags with a `prompt` property can participate in interactive mode.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* cli.addFlag({
|
|
407
|
+
* name: "environment",
|
|
408
|
+
* options: ["--env", "-e"],
|
|
409
|
+
* type: "string",
|
|
410
|
+
* promptSequence: 1,
|
|
411
|
+
* prompt: async (ctx) => ({
|
|
412
|
+
* type: "select",
|
|
413
|
+
* message: "Select environment:",
|
|
414
|
+
* options: ["staging", "production"]
|
|
415
|
+
* })
|
|
416
|
+
* });
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
export interface IPromptableFlag extends IFlag {
|
|
420
|
+
/**
|
|
421
|
+
* Prompt configuration factory.
|
|
422
|
+
* If provided, this flag can participate in interactive mode.
|
|
423
|
+
* Called at prompt time to get the configuration for @clack/prompts.
|
|
424
|
+
*
|
|
425
|
+
* The context (`ctx`) includes `promptAnswers` with previous answers,
|
|
426
|
+
* enabling conditional prompts based on earlier selections.
|
|
427
|
+
*/
|
|
428
|
+
prompt?: (ctx: IHandlerContext) => PromptFieldConfig | Promise<PromptFieldConfig>;
|
|
429
|
+
/**
|
|
430
|
+
* Explicit sequence order (1 = first, 2 = second, etc.)
|
|
431
|
+
* If omitted, uses the flag's position in the parser's flag array.
|
|
432
|
+
* Ties are broken by array order (first in array wins).
|
|
433
|
+
*/
|
|
434
|
+
promptSequence?: number;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Extended subcommand with interactive mode support.
|
|
438
|
+
* Configure when prompts are shown and handle cancellation.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* cli.addSubCommand({
|
|
443
|
+
* name: "deploy",
|
|
444
|
+
* description: "Deploy the application",
|
|
445
|
+
* promptWhen: "interactive-flag",
|
|
446
|
+
* parser: deployParser,
|
|
447
|
+
* onCancel: () => console.log("Deployment cancelled")
|
|
448
|
+
* });
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
export interface IInteractiveSubCommand extends ISubCommand {
|
|
452
|
+
/**
|
|
453
|
+
* When to trigger interactive prompts for this command.
|
|
454
|
+
* @default "interactive-flag"
|
|
455
|
+
*/
|
|
456
|
+
promptWhen?: PromptWhen;
|
|
457
|
+
/**
|
|
458
|
+
* Called when user cancels (Ctrl+C) during prompts.
|
|
459
|
+
* If not provided, exits gracefully with code 0.
|
|
460
|
+
*/
|
|
461
|
+
onCancel?: (ctx: IHandlerContext) => void | Promise<void>;
|
|
462
|
+
}
|
|
299
463
|
/**
|
|
300
464
|
* Generic context object passed to command handlers.
|
|
301
465
|
* @template TCurrentCommandArgs Shape of `args` for the current command, derived from its flags.
|
|
@@ -315,6 +479,11 @@ export type IHandlerContext<TCurrentCommandArgs = any, TParentCommandArgs = any>
|
|
|
315
479
|
/** Optional: The root `ArgParser` instance of the CLI. */
|
|
316
480
|
/** Indicates if the handler is being called from MCP mode (true) or CLI mode (false). */
|
|
317
481
|
isMcp?: boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Indicates if running in interactive mode (prompts were shown).
|
|
484
|
+
* Only true when interactive prompts were triggered and completed.
|
|
485
|
+
*/
|
|
486
|
+
isInteractive?: boolean;
|
|
318
487
|
/**
|
|
319
488
|
* Get a flag value with proper resolution priority (CLI flag > ENV > default).
|
|
320
489
|
* Only available in MCP mode when isMcp is true.
|
|
@@ -345,6 +514,30 @@ export type IHandlerContext<TCurrentCommandArgs = any, TParentCommandArgs = any>
|
|
|
345
514
|
* const userInputPath = path.resolve(ctx.rootPath, ctx.args.input);
|
|
346
515
|
*/
|
|
347
516
|
rootPath?: string;
|
|
517
|
+
/**
|
|
518
|
+
* System flags that were detected during parsing.
|
|
519
|
+
* These are flags that start with --s- and are processed internally by ArgParser.
|
|
520
|
+
* They are made available to handlers for inspection and debugging.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* // User runs: my-cli --s-debug --s-mcp-serve
|
|
524
|
+
* // In handler:
|
|
525
|
+
* console.log(ctx.systemArgs); // { debug: true, mcpServe: true }
|
|
526
|
+
*/
|
|
527
|
+
systemArgs?: ISystemArgs;
|
|
528
|
+
/**
|
|
529
|
+
* Answers collected from interactive prompts.
|
|
530
|
+
* Populated sequentially as prompts are answered.
|
|
531
|
+
* Available to subsequent prompts for conditional logic.
|
|
532
|
+
* Also available to the final handler.
|
|
533
|
+
*
|
|
534
|
+
* Keys are flag names, values are the user's answers.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* // After prompts: environment="staging", version="1.2.3"
|
|
538
|
+
* console.log(ctx.promptAnswers); // { environment: "staging", version: "1.2.3" }
|
|
539
|
+
*/
|
|
540
|
+
promptAnswers?: Record<string, any>;
|
|
348
541
|
/**
|
|
349
542
|
* Data-safe logger instance.
|
|
350
543
|
* In MCP mode, this logger ensures STDOUT safety by routing logs to STDERR or a file.
|
|
@@ -478,6 +671,37 @@ export interface ISubCommand<TSubCommandFlags extends FlagsArray = FlagsArray, T
|
|
|
478
671
|
};
|
|
479
672
|
/** MCP tool generation options for DXT generation */
|
|
480
673
|
mcpToolOptions?: any;
|
|
674
|
+
/**
|
|
675
|
+
* When to trigger interactive prompts for this command.
|
|
676
|
+
* - `"interactive-flag"` (default): Prompts shown only when `--interactive` or `-i` flag is present
|
|
677
|
+
* - `"missing"`: Prompts shown when any promptable flag is missing a value
|
|
678
|
+
* - `"always"`: Always show prompts (overrides CLI args for promptable flags)
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```typescript
|
|
682
|
+
* cli.addSubCommand({
|
|
683
|
+
* name: "deploy",
|
|
684
|
+
* description: "Deploy the application",
|
|
685
|
+
* promptWhen: "interactive-flag",
|
|
686
|
+
* parser: deployParser
|
|
687
|
+
* });
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
promptWhen?: PromptWhen;
|
|
691
|
+
/**
|
|
692
|
+
* Called when user cancels (Ctrl+C) during prompts.
|
|
693
|
+
* If not provided, exits gracefully with code 0.
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* ```typescript
|
|
697
|
+
* cli.addSubCommand({
|
|
698
|
+
* name: "deploy",
|
|
699
|
+
* parser: deployParser,
|
|
700
|
+
* onCancel: (ctx) => console.log("Deployment cancelled by user")
|
|
701
|
+
* });
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
onCancel?: (ctx: IHandlerContext) => void | Promise<void>;
|
|
481
705
|
}
|
|
482
706
|
/**
|
|
483
707
|
* Result of parsing operations that replaces process.exit() calls.
|