@clerc/core 1.0.0-beta.14 → 1.0.0-beta.15
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.d.ts +15 -5
- package/dist/index.js +6 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ import { ErrorHandler as ErrorHandler$1 } from "lite-emit";
|
|
|
6
6
|
declare class InvalidSchemaError extends Error {
|
|
7
7
|
constructor(message: string);
|
|
8
8
|
}
|
|
9
|
+
declare class MissingRequiredFlagError extends Error {
|
|
10
|
+
constructor(name: string);
|
|
11
|
+
}
|
|
9
12
|
//#endregion
|
|
10
13
|
//#region ../parser/src/flag-types.d.ts
|
|
11
14
|
/**
|
|
@@ -79,6 +82,8 @@ interface BaseFlagOptions<T extends FlagType = FlagType> {
|
|
|
79
82
|
alias?: MaybeArray<string>;
|
|
80
83
|
/** The default value of the flag. */
|
|
81
84
|
default?: unknown;
|
|
85
|
+
/** Whether the flag is required. */
|
|
86
|
+
required?: boolean;
|
|
82
87
|
}
|
|
83
88
|
type FlagOptions = (BaseFlagOptions<BooleanConstructor> & {
|
|
84
89
|
/**
|
|
@@ -149,13 +154,15 @@ type IsTypeAny<T extends FlagDefinitionValue> = IsAny<T> extends true ? true : T
|
|
|
149
154
|
} ? IsAny<Type> extends true ? true : false : false;
|
|
150
155
|
type _InferFlags<T extends FlagsDefinition> = { [K in keyof T]: IsTypeAny<T[K]> extends true ? any : T[K] extends readonly [BooleanConstructor] | {
|
|
151
156
|
type: readonly [BooleanConstructor];
|
|
152
|
-
} ? number : T[K] extends ObjectConstructor | {
|
|
157
|
+
} ? number | InferFlagDefault<T[K], never> : T[K] extends ObjectConstructor | {
|
|
153
158
|
type: ObjectConstructor;
|
|
154
|
-
} ? ObjectInputType : T[K] extends readonly [FlagType<infer U>] | {
|
|
159
|
+
} ? ObjectInputType | InferFlagDefault<T[K], never> : T[K] extends readonly [FlagType<infer U>] | {
|
|
155
160
|
type: readonly [FlagType<infer U>];
|
|
156
161
|
} ? U[] | InferFlagDefault<T[K], never> : T[K] extends FlagType<infer U> | {
|
|
157
162
|
type: FlagType<infer U>;
|
|
158
|
-
} ? U | InferFlagDefault<T[K], [U] extends [boolean] ? never :
|
|
163
|
+
} ? U | InferFlagDefault<T[K], [U] extends [boolean] ? never : T[K] extends {
|
|
164
|
+
required: true;
|
|
165
|
+
} ? never : undefined> : never };
|
|
159
166
|
/**
|
|
160
167
|
* An advanced utility type that infers the exact type of the `flags` object in the parsed result,
|
|
161
168
|
* based on the provided `flags` configuration object T.
|
|
@@ -177,7 +184,7 @@ declare function createParser<T extends FlagsDefinition>(options?: ParserOptions
|
|
|
177
184
|
};
|
|
178
185
|
declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
|
|
179
186
|
declare namespace index_d_exports {
|
|
180
|
-
export { BaseFlagOptions, Choices, DOUBLE_DASH, FlagDefaultValue, FlagDefinitionValue, FlagOptions, FlagType, FlagTypeFunction, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, RawInputType, UNKNOWN_FLAG, createParser, parse };
|
|
187
|
+
export { BaseFlagOptions, Choices, DOUBLE_DASH, FlagDefaultValue, FlagDefinitionValue, FlagOptions, FlagType, FlagTypeFunction, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, RawInputType, UNKNOWN_FLAG, createParser, parse };
|
|
181
188
|
}
|
|
182
189
|
//#endregion
|
|
183
190
|
//#region src/types/clerc.d.ts
|
|
@@ -199,6 +206,7 @@ type InferParameters<T extends readonly string[]> = T extends readonly (infer U
|
|
|
199
206
|
//#region src/types/context.d.ts
|
|
200
207
|
type AddStringIndex<T> = T & Record<string, any>;
|
|
201
208
|
type InferFlagsWithGlobal<C extends Command, GF extends ClercFlagsDefinition> = AddStringIndex<InferFlags<NonNullable<C["flags"]> & Omit<GF, keyof NonNullable<C["flags"]>>>>;
|
|
209
|
+
interface ContextStore {}
|
|
202
210
|
interface BaseContext<C extends Command = Command, GF extends ClercFlagsDefinition = {}> {
|
|
203
211
|
resolved: boolean;
|
|
204
212
|
command?: C;
|
|
@@ -208,6 +216,7 @@ interface BaseContext<C extends Command = Command, GF extends ClercFlagsDefiniti
|
|
|
208
216
|
ignored: string[];
|
|
209
217
|
rawParsed: ParsedResult<InferFlagsWithGlobal<C, GF>>;
|
|
210
218
|
missingParameters: boolean;
|
|
219
|
+
store: ContextStore;
|
|
211
220
|
}
|
|
212
221
|
//#endregion
|
|
213
222
|
//#region src/types/command.d.ts
|
|
@@ -275,6 +284,7 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
275
284
|
get _version(): string;
|
|
276
285
|
get _commands(): CommandsMap;
|
|
277
286
|
get _globalFlags(): GlobalFlags;
|
|
287
|
+
get store(): ContextStore;
|
|
278
288
|
static create(options?: CreateOptions): Clerc;
|
|
279
289
|
name(name: string): this;
|
|
280
290
|
scriptName(scriptName: string): this;
|
|
@@ -321,4 +331,4 @@ declare function createStopAtFirstParameter(): IgnoreFunction;
|
|
|
321
331
|
//#region src/plugin.d.ts
|
|
322
332
|
declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
323
333
|
//#endregion
|
|
324
|
-
export { BaseContext, Choices, Clerc, ClercFlagOptions, ClercFlagOptionsWithDescription, ClercFlagsDefinition, ClercGlobalFlagDefinitionValue, Command, CommandCustomOptions, CommandHandler, CommandHandlerContext, CommandOptions, CommandWithHandler, CommandsMap, CommandsRecord, type CreateOptions, DOUBLE_DASH, ErrorHandler, FlagCustomOptions, InferParameters, Interceptor, InterceptorContext, InterceptorHandler, InterceptorNext, InterceptorObject, InvalidCommandError, InvalidParametersError, InvalidSchemaError, KNOWN_FLAG, MakeEmitterEvents, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, type ParseOptions, type index_d_exports as Parser, Plugin, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, resolveCommand };
|
|
334
|
+
export { BaseContext, Choices, Clerc, ClercFlagOptions, ClercFlagOptionsWithDescription, ClercFlagsDefinition, ClercGlobalFlagDefinitionValue, Command, CommandCustomOptions, CommandHandler, CommandHandlerContext, CommandOptions, CommandWithHandler, CommandsMap, CommandsRecord, ContextStore, type CreateOptions, DOUBLE_DASH, ErrorHandler, FlagCustomOptions, InferParameters, Interceptor, InterceptorContext, InterceptorHandler, InterceptorNext, InterceptorObject, InvalidCommandError, InvalidParametersError, InvalidSchemaError, KNOWN_FLAG, MakeEmitterEvents, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, type ParseOptions, type index_d_exports as Parser, Plugin, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, resolveCommand };
|
package/dist/index.js
CHANGED
|
@@ -157,6 +157,7 @@ var Clerc = class Clerc {
|
|
|
157
157
|
#commands = /* @__PURE__ */ new Map();
|
|
158
158
|
#emitter = new LiteEmit({ errorHandler: (error) => this.#handleError(error) });
|
|
159
159
|
#globalFlags = {};
|
|
160
|
+
#store = {};
|
|
160
161
|
#interceptors = [];
|
|
161
162
|
#errorHandlers = [];
|
|
162
163
|
#name = "";
|
|
@@ -187,6 +188,9 @@ var Clerc = class Clerc {
|
|
|
187
188
|
get _globalFlags() {
|
|
188
189
|
return this.#globalFlags;
|
|
189
190
|
}
|
|
191
|
+
get store() {
|
|
192
|
+
return this.#store;
|
|
193
|
+
}
|
|
190
194
|
static create(options) {
|
|
191
195
|
return new Clerc(options);
|
|
192
196
|
}
|
|
@@ -300,7 +304,8 @@ var Clerc = class Clerc {
|
|
|
300
304
|
flags: parsed.flags,
|
|
301
305
|
ignored: parsed.ignored,
|
|
302
306
|
rawParsed: parsed,
|
|
303
|
-
missingParameters: !!parametersError
|
|
307
|
+
missingParameters: !!parametersError,
|
|
308
|
+
store: { ...this.#store }
|
|
304
309
|
};
|
|
305
310
|
const emitInterceptor = {
|
|
306
311
|
enforce: "post",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc core",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"lite-emit": "^3.1.0",
|
|
48
|
-
"@clerc/parser": "^1.0.0-beta.
|
|
48
|
+
"@clerc/parser": "^1.0.0-beta.15"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"is-platform": "^1.0.0",
|
|
52
|
-
"@clerc/utils": "1.0.0-beta.
|
|
52
|
+
"@clerc/utils": "1.0.0-beta.15"
|
|
53
53
|
}
|
|
54
54
|
}
|