@clerc/core 1.0.0-beta.13 → 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 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
  /**
@@ -43,7 +46,9 @@ type UnionToIntersection<U$1> = (U$1 extends any ? (k: U$1) => void : never) ext
43
46
  type CamelCase<S extends string> = S extends `${infer Head} ${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelCase<Tail>>}` : S;
44
47
  //#endregion
45
48
  //#region ../parser/src/types.d.ts
46
- type FlagDefaultValue<T = unknown> = T | (() => T);
49
+ type FlagDefaultValue<T = unknown> = T | ((() => T) & {
50
+ display?: string;
51
+ });
47
52
  /**
48
53
  * Defines how a string input is converted to the target type T.
49
54
  *
@@ -54,7 +59,7 @@ type FlagTypeFunction<T = unknown> = ((value: string) => T) & {
54
59
  * Optional display name for the type, useful in help output.
55
60
  * If provided, this will be shown instead of the function name.
56
61
  */
57
- displayName?: string;
62
+ display?: string;
58
63
  };
59
64
  /**
60
65
  * A callback function to conditionally stop parsing.
@@ -77,6 +82,8 @@ interface BaseFlagOptions<T extends FlagType = FlagType> {
77
82
  alias?: MaybeArray<string>;
78
83
  /** The default value of the flag. */
79
84
  default?: unknown;
85
+ /** Whether the flag is required. */
86
+ required?: boolean;
80
87
  }
81
88
  type FlagOptions = (BaseFlagOptions<BooleanConstructor> & {
82
89
  /**
@@ -147,13 +154,15 @@ type IsTypeAny<T extends FlagDefinitionValue> = IsAny<T> extends true ? true : T
147
154
  } ? IsAny<Type> extends true ? true : false : false;
148
155
  type _InferFlags<T extends FlagsDefinition> = { [K in keyof T]: IsTypeAny<T[K]> extends true ? any : T[K] extends readonly [BooleanConstructor] | {
149
156
  type: readonly [BooleanConstructor];
150
- } ? number : T[K] extends ObjectConstructor | {
157
+ } ? number | InferFlagDefault<T[K], never> : T[K] extends ObjectConstructor | {
151
158
  type: ObjectConstructor;
152
- } ? ObjectInputType : T[K] extends readonly [FlagType<infer U>] | {
159
+ } ? ObjectInputType | InferFlagDefault<T[K], never> : T[K] extends readonly [FlagType<infer U>] | {
153
160
  type: readonly [FlagType<infer U>];
154
161
  } ? U[] | InferFlagDefault<T[K], never> : T[K] extends FlagType<infer U> | {
155
162
  type: FlagType<infer U>;
156
- } ? U | InferFlagDefault<T[K], [U] extends [boolean] ? never : undefined> : never };
163
+ } ? U | InferFlagDefault<T[K], [U] extends [boolean] ? never : T[K] extends {
164
+ required: true;
165
+ } ? never : undefined> : never };
157
166
  /**
158
167
  * An advanced utility type that infers the exact type of the `flags` object in the parsed result,
159
168
  * based on the provided `flags` configuration object T.
@@ -175,7 +184,7 @@ declare function createParser<T extends FlagsDefinition>(options?: ParserOptions
175
184
  };
176
185
  declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
177
186
  declare namespace index_d_exports {
178
- 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 };
179
188
  }
180
189
  //#endregion
181
190
  //#region src/types/clerc.d.ts
@@ -197,6 +206,7 @@ type InferParameters<T extends readonly string[]> = T extends readonly (infer U
197
206
  //#region src/types/context.d.ts
198
207
  type AddStringIndex<T> = T & Record<string, any>;
199
208
  type InferFlagsWithGlobal<C extends Command, GF extends ClercFlagsDefinition> = AddStringIndex<InferFlags<NonNullable<C["flags"]> & Omit<GF, keyof NonNullable<C["flags"]>>>>;
209
+ interface ContextStore {}
200
210
  interface BaseContext<C extends Command = Command, GF extends ClercFlagsDefinition = {}> {
201
211
  resolved: boolean;
202
212
  command?: C;
@@ -206,6 +216,7 @@ interface BaseContext<C extends Command = Command, GF extends ClercFlagsDefiniti
206
216
  ignored: string[];
207
217
  rawParsed: ParsedResult<InferFlagsWithGlobal<C, GF>>;
208
218
  missingParameters: boolean;
219
+ store: ContextStore;
209
220
  }
210
221
  //#endregion
211
222
  //#region src/types/command.d.ts
@@ -273,6 +284,7 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
273
284
  get _version(): string;
274
285
  get _commands(): CommandsMap;
275
286
  get _globalFlags(): GlobalFlags;
287
+ get store(): ContextStore;
276
288
  static create(options?: CreateOptions): Clerc;
277
289
  name(name: string): this;
278
290
  scriptName(scriptName: string): this;
@@ -319,4 +331,4 @@ declare function createStopAtFirstParameter(): IgnoreFunction;
319
331
  //#region src/plugin.d.ts
320
332
  declare const definePlugin: (plugin: Plugin) => Plugin;
321
333
  //#endregion
322
- 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.13",
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.13"
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.13"
52
+ "@clerc/utils": "1.0.0-beta.15"
53
53
  }
54
54
  }