@alcyone-labs/arg-parser 1.2.0 → 2.1.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.
@@ -1,165 +0,0 @@
1
- import { z } from "zod";
2
- export type ArgParserInstance = any;
3
- export declare const zodFlagSchema: z.ZodEffects<z.ZodObject<{
4
- name: z.ZodString;
5
- allowLigature: z.ZodDefault<z.ZodBoolean>;
6
- allowMultiple: z.ZodDefault<z.ZodBoolean>;
7
- description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
8
- options: z.ZodArray<z.ZodString, "many">;
9
- defaultValue: z.ZodOptional<z.ZodAny>;
10
- type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
11
- mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
12
- flagOnly: z.ZodDefault<z.ZodBoolean>;
13
- validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
14
- enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
15
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
16
- name: z.ZodString;
17
- allowLigature: z.ZodDefault<z.ZodBoolean>;
18
- allowMultiple: z.ZodDefault<z.ZodBoolean>;
19
- description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
20
- options: z.ZodArray<z.ZodString, "many">;
21
- defaultValue: z.ZodOptional<z.ZodAny>;
22
- type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
23
- mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
24
- flagOnly: z.ZodDefault<z.ZodBoolean>;
25
- validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
26
- enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
27
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
28
- name: z.ZodString;
29
- allowLigature: z.ZodDefault<z.ZodBoolean>;
30
- allowMultiple: z.ZodDefault<z.ZodBoolean>;
31
- description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
32
- options: z.ZodArray<z.ZodString, "many">;
33
- defaultValue: z.ZodOptional<z.ZodAny>;
34
- type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
35
- mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
36
- flagOnly: z.ZodDefault<z.ZodBoolean>;
37
- validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
38
- enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
39
- }, z.ZodTypeAny, "passthrough">>, {
40
- [key: string]: any;
41
- }, z.objectInputType<{
42
- name: z.ZodString;
43
- allowLigature: z.ZodDefault<z.ZodBoolean>;
44
- allowMultiple: z.ZodDefault<z.ZodBoolean>;
45
- description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
46
- options: z.ZodArray<z.ZodString, "many">;
47
- defaultValue: z.ZodOptional<z.ZodAny>;
48
- type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
49
- mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
50
- flagOnly: z.ZodDefault<z.ZodBoolean>;
51
- validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
52
- enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
53
- }, z.ZodTypeAny, "passthrough">>;
54
- /**
55
- * The raw input type for defining a flag, before Zod processing (aliases, defaults).
56
- */
57
- export type IFlagCore = z.input<typeof zodFlagSchema>;
58
- /**
59
- * The type of the `type` property in a ProcessedFlagCore object.
60
- * This represents all valid forms the `type` property can take after Zod processing.
61
- */
62
- export type TParsedArgsTypeFromFlagDef = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor | ((value: string) => any) | "string" | "number" | "boolean" | "array" | "object";
63
- /**
64
- * The core type of a flag after Zod processing (defaults applied, aliases resolved),
65
- * but before some properties are made more specific (like `type` constructor to actual type).
66
- * This type is output by `zodFlagSchema.parse()`.
67
- */
68
- export type ProcessedFlagCore = Omit<z.output<typeof zodFlagSchema>, "type"> & {
69
- type: TParsedArgsTypeFromFlagDef;
70
- };
71
- /**
72
- * The user-facing type for defining a flag. It includes aliases like `default` and `required`.
73
- * The `handler` property is removed as handlers are typically associated with commands/subcommands, not individual flags.
74
- */
75
- export type IFlag = IFlagCore & {
76
- /** @alias defaultValue */
77
- default?: any;
78
- /** @alias mandatory */
79
- required?: boolean | ((parsedArgs: TParsedArgs<any>) => boolean);
80
- };
81
- /**
82
- * A more refined type for a flag after it has been fully processed by ArgParser,
83
- * particularly its `type` property and validation/enum/mandatory functions.
84
- * This is the type that ArgParser would internally work with for parsing and type extraction.
85
- */
86
- export type ProcessedFlag = Omit<ProcessedFlagCore, "validate" | "enum" | "mandatory"> & {
87
- validate?: (value: any, parsedArgs?: TParsedArgs<ProcessedFlag[]>) => boolean | string | void | Promise<boolean | string | void>;
88
- enum?: any[];
89
- mandatory?: boolean | ((parsedArgs: TParsedArgs<ProcessedFlag[]>) => boolean);
90
- };
91
- /**
92
- * Resolves the TypeScript type from a flag's `type` definition.
93
- */
94
- export type ResolveType<T extends TParsedArgsTypeFromFlagDef> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends ArrayConstructor ? any[] : T extends ObjectConstructor ? Record<string, any> : T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "array" ? any[] : T extends "object" ? Record<string, any> : T extends (value: string) => infer R ? R : any;
95
- /**
96
- * Extracts the final TypeScript type for a flag's value based on its definition,
97
- * considering `flagOnly` and `allowMultiple` properties.
98
- */
99
- export type ExtractFlagType<TFlag extends ProcessedFlag> = TFlag["flagOnly"] extends true ? TFlag["allowMultiple"] extends true ? boolean[] : boolean : TFlag["allowMultiple"] extends true ? Array<ResolveType<TFlag["type"]>> : ResolveType<TFlag["type"]>;
100
- /**
101
- * Represents the structured object of parsed arguments.
102
- * Keys are flag names, and values are their parsed and typed values.
103
- * `TFlags` should be the array of `ProcessedFlag` definitions for the specific command.
104
- */
105
- export type TParsedArgs<TFlags extends readonly ProcessedFlag[]> = {
106
- [K in TFlags[number]["name"]]: ExtractFlagType<Extract<TFlags[number], {
107
- name: K;
108
- }>>;
109
- };
110
- /**
111
- * Generic context object passed to command handlers.
112
- * @template TCurrentCommandArgs Shape of `args` for the current command, derived from its flags.
113
- * @template TParentCommandArgs Shape of `parentArgs` from the parent command, if any.
114
- */
115
- export type IHandlerContext<TCurrentCommandArgs extends Record<string, any> = Record<string, any>, TParentCommandArgs extends Record<string, any> = Record<string, any>> = {
116
- /** Parsed arguments specific to the current command. */
117
- args: TCurrentCommandArgs;
118
- /** Parsed arguments from the parent command, if this is a subcommand. */
119
- parentArgs?: TParentCommandArgs;
120
- /** The sequence of command names that led to this handler. */
121
- commandChain: string[];
122
- /** The `ArgParser` instance that invoked this handler (could be a subcommand's parser). */
123
- parser: ArgParserInstance;
124
- /** The parent `ArgParser` instance, if this is a subcommand handler. */
125
- parentParser?: ArgParserInstance;
126
- /** Optional: The root `ArgParser` instance of the CLI. */
127
- /** Indicates if the handler is being called from MCP mode (true) or CLI mode (false). */
128
- isMcp?: boolean;
129
- };
130
- /**
131
- * Generic type for the collection of processed flags that an ArgParser instance manages.
132
- */
133
- export type FlagsArray = readonly ProcessedFlag[];
134
- /**
135
- * Defines a subcommand within an ArgParser setup.
136
- * @template TSubCommandFlags Flags defined specifically FOR this subcommand.
137
- * @template TParentCommandFlags Flags defined for the PARENT of this subcommand.
138
- * @template THandlerReturn The expected return type of the subcommand's handler.
139
- */
140
- export interface ISubCommand<TSubCommandFlags extends FlagsArray = FlagsArray, TParentCommandFlags extends FlagsArray = FlagsArray, THandlerReturn = any> {
141
- name: string;
142
- description?: string;
143
- /** The ArgParser instance for this subcommand, typed with its own flags. */
144
- parser: ArgParserInstance;
145
- /** Handler function for this subcommand. */
146
- handler?: (ctx: IHandlerContext<TParsedArgs<TSubCommandFlags>, TParsedArgs<TParentCommandFlags>>) => THandlerReturn | Promise<THandlerReturn>;
147
- /** Internal flag to identify MCP subcommands for proper exclusion from tool generation */
148
- isMcp?: boolean;
149
- /** MCP server information for DXT generation */
150
- mcpServerInfo?: {
151
- name: string;
152
- version: string;
153
- description?: string;
154
- };
155
- /** MCP tool generation options for DXT generation */
156
- mcpToolOptions?: any;
157
- }
158
- /**
159
- * Type for the main handler of an ArgParser instance (root command or a command defined by an ArgParser).
160
- * @template TParserFlags Flags defined for this ArgParser instance.
161
- * @template TParentParserFlags Flags of the parent parser, if this parser is used as a subcommand.
162
- * @template THandlerReturn The expected return type of the handler.
163
- */
164
- export type MainHandler<TParserFlags extends FlagsArray = FlagsArray, TParentParserFlags extends FlagsArray = FlagsArray, THandlerReturn = any> = (ctx: IHandlerContext<TParsedArgs<TParserFlags>, TParsedArgs<TParentParserFlags>>) => THandlerReturn | Promise<THandlerReturn>;
165
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAEpC,eAAO,MAAM,aA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