@clerc/core 1.0.0-beta.17 → 1.0.0-beta.19
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/chunk-CYeTv9WL.js +42 -0
- package/dist/index.d.ts +254 -87
- package/dist/index.js +18 -80
- package/package.json +4 -4
- package/dist/chunk-BAz01cYq.js +0 -18
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (all, symbols) => {
|
|
7
|
+
let target = {};
|
|
8
|
+
for (var name in all) {
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (symbols) {
|
|
15
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
22
|
+
key = keys[i];
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: ((k) => from[k]).bind(null, key),
|
|
26
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __reExport = (target, mod, secondTarget, symbols) => {
|
|
34
|
+
if (symbols) {
|
|
35
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
36
|
+
secondTarget && __defProp(secondTarget, Symbol.toStringTag, { value: "Module" });
|
|
37
|
+
}
|
|
38
|
+
__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { __reExport as n, __export as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as __reExport, t as __export } from "./chunk-CYeTv9WL.js";
|
|
2
|
+
import { Clerc as Clerc$1, CreateOptions as CreateOptions$1, Plugin as Plugin$1 } from "@clerc/core";
|
|
2
3
|
|
|
3
4
|
//#region ../parser/src/errors.d.ts
|
|
4
5
|
declare class InvalidSchemaError extends Error {
|
|
@@ -8,23 +9,6 @@ declare class MissingRequiredFlagError extends Error {
|
|
|
8
9
|
constructor(name: string);
|
|
9
10
|
}
|
|
10
11
|
//#endregion
|
|
11
|
-
//#region ../parser/src/flag-types.d.ts
|
|
12
|
-
/**
|
|
13
|
-
* Creates a Enum type function that validates the input against allowed values.
|
|
14
|
-
* The display name will be formatted as "value1 | value2 | ..." for help output.
|
|
15
|
-
*
|
|
16
|
-
* @param values - Array of allowed string values
|
|
17
|
-
* @returns A FlagTypeFunction that validates and returns the input value
|
|
18
|
-
* @throws {Error} If the value is not in the allowed values list
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const format = Enum(['json', 'yaml', 'xml']);
|
|
23
|
-
* // Help output will show: json | yaml | xml
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
declare function Enum<T extends string>(...values: T[]): FlagTypeFunction<T>;
|
|
27
|
-
//#endregion
|
|
28
12
|
//#region ../utils/src/types/type-fest.d.ts
|
|
29
13
|
type LiteralUnion<LiteralType, BaseType> = LiteralType | (BaseType & Record<never, never>);
|
|
30
14
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
@@ -43,6 +27,11 @@ type PartialRequired<T, K$1 extends keyof T> = T & { [P in K$1]-?: T[P] };
|
|
|
43
27
|
type UnionToIntersection<U$1> = (U$1 extends any ? (k: U$1) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
44
28
|
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;
|
|
45
29
|
//#endregion
|
|
30
|
+
//#region ../parser/src/iterator.d.ts
|
|
31
|
+
declare const KNOWN_FLAG = "known-flag";
|
|
32
|
+
declare const UNKNOWN_FLAG = "unknown-flag";
|
|
33
|
+
declare const PARAMETER = "parameter";
|
|
34
|
+
//#endregion
|
|
46
35
|
//#region ../parser/src/types.d.ts
|
|
47
36
|
interface FlagDefaultValueFunction<T> {
|
|
48
37
|
(): T;
|
|
@@ -172,10 +161,40 @@ type _InferFlags<T extends FlagsDefinition> = { [K in keyof T]: IsTypeAny<T[K]>
|
|
|
172
161
|
*/
|
|
173
162
|
type InferFlags<T extends FlagsDefinition> = Prettify<_InferFlags<T>>;
|
|
174
163
|
//#endregion
|
|
175
|
-
//#region ../parser/src/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
164
|
+
//#region ../parser/src/flag-types.d.ts
|
|
165
|
+
/**
|
|
166
|
+
* Creates a Enum type function that validates the input against allowed values.
|
|
167
|
+
* The display name will be formatted as "value1 | value2 | ..." for help output.
|
|
168
|
+
*
|
|
169
|
+
* @param values - Array of allowed string values
|
|
170
|
+
* @returns A FlagTypeFunction that validates and returns the input value
|
|
171
|
+
* @throws {Error} If the value is not in the allowed values list
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const format = Enum(['json', 'yaml', 'xml']);
|
|
176
|
+
* // Help output will show: json | yaml | xml
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
declare function Enum<T extends string>(...values: T[]): FlagTypeFunction<T>;
|
|
180
|
+
/**
|
|
181
|
+
* Creates a range type function that validates the input is a number within the specified range.
|
|
182
|
+
*
|
|
183
|
+
* @param min - The minimum acceptable value (inclusive)
|
|
184
|
+
* @param max - The maximum acceptable value (inclusive)
|
|
185
|
+
* @returns A FlagTypeFunction that validates the input value
|
|
186
|
+
* @throws {Error} If the value is not a number or is outside the specified range
|
|
187
|
+
*/
|
|
188
|
+
declare function Range(min: number, max: number): FlagTypeFunction<number>;
|
|
189
|
+
/**
|
|
190
|
+
* Creates a regex type function that validates the input against the provided pattern.
|
|
191
|
+
*
|
|
192
|
+
* @param pattern - The regular expression pattern to validate against
|
|
193
|
+
* @param description - Optional description for display purposes
|
|
194
|
+
* @returns A FlagTypeFunction that validates the input value
|
|
195
|
+
* @throws {Error} If the value does not match the regex pattern
|
|
196
|
+
*/
|
|
197
|
+
declare function Regex(pattern: RegExp, description?: string): FlagTypeFunction<string>;
|
|
179
198
|
//#endregion
|
|
180
199
|
//#region ../parser/src/parse.d.ts
|
|
181
200
|
declare const DOUBLE_DASH = "--";
|
|
@@ -185,7 +204,7 @@ declare function createParser<T extends FlagsDefinition>(options?: ParserOptions
|
|
|
185
204
|
};
|
|
186
205
|
declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
|
|
187
206
|
declare namespace index_d_exports {
|
|
188
|
-
export { BaseFlagOptions, DOUBLE_DASH, Enum, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagType, FlagTypeFunction, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, RawInputType, UNKNOWN_FLAG, createParser, parse };
|
|
207
|
+
export { BaseFlagOptions, DOUBLE_DASH, Enum, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagType, FlagTypeFunction, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, Range, RawInputType, Regex, UNKNOWN_FLAG, createParser, parse };
|
|
189
208
|
}
|
|
190
209
|
//#endregion
|
|
191
210
|
//#region src/types/clerc.d.ts
|
|
@@ -193,32 +212,20 @@ type ErrorHandler = (error: unknown) => void;
|
|
|
193
212
|
//#endregion
|
|
194
213
|
//#region src/types/flag.d.ts
|
|
195
214
|
interface FlagCustomOptions {}
|
|
196
|
-
type ClercFlagOptions = FlagOptions &
|
|
197
|
-
type ClercGlobalFlagDefinitionValue = ClercFlagOptions | FlagType;
|
|
198
|
-
type ClercFlagOptionsWithDescription = ClercFlagOptions & {
|
|
215
|
+
type ClercFlagOptions = FlagOptions & {
|
|
199
216
|
description?: string;
|
|
200
|
-
};
|
|
201
|
-
type
|
|
202
|
-
|
|
203
|
-
//#region src/types/constraint.d.ts
|
|
204
|
-
/**
|
|
205
|
-
* Creates an enum constraint function that validates the input against a set of allowed values.
|
|
206
|
-
*
|
|
207
|
-
* @template T - The union type of allowed string values. Just a marker type to help with inference.
|
|
208
|
-
*/
|
|
209
|
-
interface ConstraintFunction<T = string> {
|
|
210
|
-
(value: string): void;
|
|
211
|
-
display?: string;
|
|
212
|
-
}
|
|
217
|
+
} & FlagCustomOptions;
|
|
218
|
+
type ClercFlagDefinitionValue = ClercFlagOptions | FlagType;
|
|
219
|
+
type ClercFlagsDefinition = Record<string, ClercFlagDefinitionValue>;
|
|
213
220
|
//#endregion
|
|
214
221
|
//#region src/types/parameters.d.ts
|
|
215
222
|
type InferStringParameter<T extends string, Type$1 = string> = T extends `<${infer Name extends string}...>` | `[${infer Name extends string}...]` ? Record<CamelCase<Name>, Type$1[]> : T extends `<${infer Name extends string}>` ? Record<CamelCase<Name>, Type$1> : T extends `[${infer Name extends string}]` ? Record<CamelCase<Name>, Type$1 | undefined> : never;
|
|
216
|
-
type InferParameter<T extends Parameter> = T extends string ? InferStringParameter<T> : T extends ParameterDefinition ? T["
|
|
223
|
+
type InferParameter<T extends Parameter> = T extends string ? InferStringParameter<T> : T extends ParameterDefinition ? T["type"] extends FlagTypeFunction<infer U> ? InferStringParameter<T["key"], U> : InferStringParameter<T["key"]> : never;
|
|
217
224
|
type InferParameters<T extends readonly Parameter[]> = T extends readonly (infer U extends Parameter)[] ? Prettify<UnionToIntersection<InferParameter<U>>> : never;
|
|
218
225
|
interface ParameterDefinition {
|
|
219
226
|
key: string;
|
|
220
227
|
description?: string;
|
|
221
|
-
|
|
228
|
+
type?: FlagTypeFunction;
|
|
222
229
|
}
|
|
223
230
|
type Parameter = string | ParameterDefinition;
|
|
224
231
|
//#endregion
|
|
@@ -235,7 +242,7 @@ interface BaseContext<C extends Command = Command, GF extends ClercFlagsDefiniti
|
|
|
235
242
|
ignored: string[];
|
|
236
243
|
rawParsed: ParsedResult<InferFlagsWithGlobal<C, GF>>;
|
|
237
244
|
missingParameters: boolean;
|
|
238
|
-
store: ContextStore
|
|
245
|
+
store: Partial<ContextStore>;
|
|
239
246
|
}
|
|
240
247
|
//#endregion
|
|
241
248
|
//#region src/types/command.d.ts
|
|
@@ -303,19 +310,19 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
303
310
|
get _version(): string;
|
|
304
311
|
get _commands(): CommandsMap;
|
|
305
312
|
get _globalFlags(): GlobalFlags;
|
|
306
|
-
get store(): ContextStore
|
|
313
|
+
get store(): Partial<ContextStore>;
|
|
307
314
|
static create(options?: CreateOptions): Clerc;
|
|
308
315
|
name(name: string): this;
|
|
309
316
|
scriptName(scriptName: string): this;
|
|
310
317
|
description(description: string): this;
|
|
311
318
|
version(version: string): this;
|
|
312
319
|
use(plugin: Plugin): this;
|
|
313
|
-
errorHandler(handler: ErrorHandler
|
|
320
|
+
errorHandler(handler: ErrorHandler): this;
|
|
314
321
|
command<Name$1 extends string, const Parameters extends readonly Parameter[], Flags extends ClercFlagsDefinition = {}>(command: CommandWithHandler<Name$1, Parameters, Flags>): Clerc<Commands & Record<string, CommandWithHandler<Name$1, Parameters, Flags>>, GlobalFlags>;
|
|
315
322
|
command<Name$1 extends string, const Parameters extends readonly Parameter[], Flags extends ClercFlagsDefinition = {}>(name: Name$1 extends keyof Commands ? ["COMMAND ALREADY EXISTS"] : Name$1, options?: CommandOptions<Parameters, Flags>): Clerc<Commands & Record<Name$1, Command<Name$1, Parameters, Flags>>, GlobalFlags>;
|
|
316
323
|
command<Name$1 extends string, const Parameters extends readonly Parameter[], Flags extends ClercFlagsDefinition = {}>(name: Name$1 extends keyof Commands ? ["COMMAND ALREADY EXISTS"] : Name$1, description: string, options?: CommandOptions<Parameters, Flags>): Clerc<Commands & Record<Name$1, Command<Name$1, Parameters, Flags>>, GlobalFlags>;
|
|
317
|
-
globalFlag<Name$1 extends string, Flag extends
|
|
318
|
-
globalFlag<Name$1 extends string, Flag extends
|
|
324
|
+
globalFlag<Name$1 extends string, Flag extends ClercFlagDefinitionValue>(name: Name$1, description: string, options: Flag): Clerc<Commands, GlobalFlags & Record<Name$1, Flag>>;
|
|
325
|
+
globalFlag<Name$1 extends string, Flag extends ClercFlagDefinitionValue>(name: Name$1, options: Flag): Clerc<Commands, GlobalFlags & Record<Name$1, Flag>>;
|
|
319
326
|
interceptor(interceptor: Interceptor<Command, GlobalFlags>): this;
|
|
320
327
|
on<Name$1 extends LiteralUnion<keyof Commands, string>>(name: Name$1, handler: CommandHandler<Commands[Name$1], GlobalFlags>): this;
|
|
321
328
|
run(): Promise<void>;
|
|
@@ -324,45 +331,6 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
324
331
|
//#endregion
|
|
325
332
|
//#region src/commands.d.ts
|
|
326
333
|
declare function resolveCommand(commandsMap: CommandsMap, parameters: string[]): [Command, string] | [undefined, undefined];
|
|
327
|
-
declare namespace constraint_d_exports {
|
|
328
|
-
export { Custom, Enum$1 as Enum, Range, Regex };
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Creates an enum constraint function that validates the input against a set of allowed values.
|
|
332
|
-
*
|
|
333
|
-
* @param values - Array of allowed string values
|
|
334
|
-
* @returns A ConstraintFunction that validates the input value
|
|
335
|
-
* @throws {Error} If the value is not in the allowed values list
|
|
336
|
-
*/
|
|
337
|
-
declare function Enum$1<T extends string>(...values: T[]): ConstraintFunction<T>;
|
|
338
|
-
/**
|
|
339
|
-
* Creates a range constraint function that validates the input is a number within the specified range.
|
|
340
|
-
*
|
|
341
|
-
* @param min - The minimum acceptable value (inclusive)
|
|
342
|
-
* @param max - The maximum acceptable value (inclusive)
|
|
343
|
-
* @returns A ConstraintFunction that validates the input value
|
|
344
|
-
* @throws {Error} If the value is not a number or is outside the specified range
|
|
345
|
-
*/
|
|
346
|
-
declare function Range(min: number, max: number): ConstraintFunction;
|
|
347
|
-
/**
|
|
348
|
-
* Creates a regex constraint function that validates the input against the provided pattern.
|
|
349
|
-
*
|
|
350
|
-
* @param pattern - The regular expression pattern to validate against
|
|
351
|
-
* @param description - Optional description for display purposes
|
|
352
|
-
* @returns A ConstraintFunction that validates the input value
|
|
353
|
-
* @throws {Error} If the value does not match the regex pattern
|
|
354
|
-
*/
|
|
355
|
-
declare function Regex(pattern: RegExp, description?: string): ConstraintFunction;
|
|
356
|
-
/**
|
|
357
|
-
* Just an utility to create custom constraints, helps you set the display name.
|
|
358
|
-
*
|
|
359
|
-
* @param validator - A function that validates the input value. Should return true if valid, false or throw an error if invalid.
|
|
360
|
-
* @param display - Optional display name for the constraint, useful in help output.
|
|
361
|
-
* @param errorMessage - Optional function to generate a custom error message when validation fails.
|
|
362
|
-
* @returns A ConstraintFunction that applies the custom validation logic.
|
|
363
|
-
* @throws {Error} If the validator returns false or throws an error.
|
|
364
|
-
*/
|
|
365
|
-
declare function Custom(validator: (value: string) => boolean | void, display?: string, errorMessage?: (value: string) => string): ConstraintFunction;
|
|
366
334
|
//#endregion
|
|
367
335
|
//#region src/errors.d.ts
|
|
368
336
|
declare class NoSuchCommandError extends Error {
|
|
@@ -382,7 +350,7 @@ declare class InvalidParametersError extends Error {
|
|
|
382
350
|
constructor(message: string);
|
|
383
351
|
}
|
|
384
352
|
declare namespace flag_types_d_exports {
|
|
385
|
-
export { Enum };
|
|
353
|
+
export { Enum, Range, Regex };
|
|
386
354
|
}
|
|
387
355
|
//#endregion
|
|
388
356
|
//#region src/helpers.d.ts
|
|
@@ -394,4 +362,203 @@ declare function createStopAtFirstParameter(): IgnoreFunction;
|
|
|
394
362
|
//#region src/plugin.d.ts
|
|
395
363
|
declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
396
364
|
//#endregion
|
|
397
|
-
|
|
365
|
+
//#region ../plugin-completions/src/index.d.ts
|
|
366
|
+
declare module "@clerc/core" {
|
|
367
|
+
interface CommandCustomOptions {
|
|
368
|
+
/**
|
|
369
|
+
* Completions options for the command.
|
|
370
|
+
*/
|
|
371
|
+
completions?: {
|
|
372
|
+
/**
|
|
373
|
+
* Whether to show the command in completions output.
|
|
374
|
+
*
|
|
375
|
+
* @default true
|
|
376
|
+
*/
|
|
377
|
+
show?: boolean;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
interface CompletionsPluginOptions {
|
|
382
|
+
/**
|
|
383
|
+
* Whether to register the `completions install` and `completions uninstall` commands.
|
|
384
|
+
* @default true
|
|
385
|
+
*/
|
|
386
|
+
managementCommands?: boolean;
|
|
387
|
+
}
|
|
388
|
+
declare const completionsPlugin: (options?: CompletionsPluginOptions) => Plugin$1;
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region ../plugin-friendly-error/src/index.d.ts
|
|
391
|
+
interface FriendlyErrorPluginOptions {
|
|
392
|
+
target?: (str: string) => void;
|
|
393
|
+
}
|
|
394
|
+
declare const friendlyErrorPlugin: ({
|
|
395
|
+
target
|
|
396
|
+
}?: FriendlyErrorPluginOptions) => Plugin$1;
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region ../plugin-help/src/types.d.ts
|
|
399
|
+
interface Formatters {
|
|
400
|
+
formatFlagType: (type: FlagType) => string;
|
|
401
|
+
formatFlagDefault: <T>(value: FlagDefaultValue<T>) => string;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* A group definition as a tuple of [key, displayName].
|
|
405
|
+
* The key is used in help options to assign items to groups.
|
|
406
|
+
* The displayName is shown in the help output.
|
|
407
|
+
*/
|
|
408
|
+
type GroupDefinition = [key: string, name: string];
|
|
409
|
+
/**
|
|
410
|
+
* Options for defining groups in help output.
|
|
411
|
+
*/
|
|
412
|
+
interface GroupsOptions {
|
|
413
|
+
/**
|
|
414
|
+
* Groups for commands.
|
|
415
|
+
* Each group is defined as `[key, name]`.
|
|
416
|
+
*/
|
|
417
|
+
commands?: GroupDefinition[];
|
|
418
|
+
/**
|
|
419
|
+
* Groups for command-specific flags.
|
|
420
|
+
* Each group is defined as `[key, name]`.
|
|
421
|
+
*/
|
|
422
|
+
flags?: GroupDefinition[];
|
|
423
|
+
/**
|
|
424
|
+
* Groups for global flags.
|
|
425
|
+
* Each group is defined as `[key, name]`.
|
|
426
|
+
*/
|
|
427
|
+
globalFlags?: GroupDefinition[];
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region ../plugin-help/src/formatters.d.ts
|
|
431
|
+
declare const defaultFormatters: Formatters;
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region ../plugin-help/src/index.d.ts
|
|
434
|
+
interface HelpOptions {
|
|
435
|
+
/**
|
|
436
|
+
* The group this item belongs to.
|
|
437
|
+
* The group must be defined in the `groups` option of `helpPlugin()`.
|
|
438
|
+
*/
|
|
439
|
+
group?: string;
|
|
440
|
+
}
|
|
441
|
+
interface CommandHelpOptions extends HelpOptions {
|
|
442
|
+
/**
|
|
443
|
+
* Whether to show the command in help output.
|
|
444
|
+
*
|
|
445
|
+
* @default true
|
|
446
|
+
*/
|
|
447
|
+
show?: boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Notes to show in the help output.
|
|
450
|
+
*/
|
|
451
|
+
notes?: string[];
|
|
452
|
+
/**
|
|
453
|
+
* Examples to show in the help output.
|
|
454
|
+
* Each example is a tuple of `[command, description]`.
|
|
455
|
+
*/
|
|
456
|
+
examples?: [string, string][];
|
|
457
|
+
}
|
|
458
|
+
declare module "@clerc/core" {
|
|
459
|
+
interface CommandCustomOptions {
|
|
460
|
+
/**
|
|
461
|
+
* Help options for the command.
|
|
462
|
+
*/
|
|
463
|
+
help?: CommandHelpOptions;
|
|
464
|
+
}
|
|
465
|
+
interface FlagCustomOptions {
|
|
466
|
+
/**
|
|
467
|
+
* Help options for the flag.
|
|
468
|
+
*/
|
|
469
|
+
help?: HelpOptions;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
interface HelpPluginOptions {
|
|
473
|
+
/**
|
|
474
|
+
* Whether to register the `help` command.
|
|
475
|
+
*
|
|
476
|
+
* @default true
|
|
477
|
+
*/
|
|
478
|
+
command?: boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Whether to register the `--help` global flag.
|
|
481
|
+
*
|
|
482
|
+
* @default true
|
|
483
|
+
*/
|
|
484
|
+
flag?: boolean;
|
|
485
|
+
/**
|
|
486
|
+
* Whether to show help when no command is specified.
|
|
487
|
+
*
|
|
488
|
+
* @default true
|
|
489
|
+
*/
|
|
490
|
+
showHelpWhenNoCommandSpecified?: boolean;
|
|
491
|
+
/**
|
|
492
|
+
* Notes to show in the help output.
|
|
493
|
+
*/
|
|
494
|
+
notes?: string[];
|
|
495
|
+
/**
|
|
496
|
+
* Examples to show in the help output.
|
|
497
|
+
* Each example is a tuple of `[command, description]`.
|
|
498
|
+
*/
|
|
499
|
+
examples?: [string, string][];
|
|
500
|
+
/**
|
|
501
|
+
* A banner to show before the help output.
|
|
502
|
+
*/
|
|
503
|
+
banner?: string;
|
|
504
|
+
/**
|
|
505
|
+
* Custom formatters for rendering help.
|
|
506
|
+
*/
|
|
507
|
+
formatters?: Partial<Formatters>;
|
|
508
|
+
/**
|
|
509
|
+
* Group definitions for commands and flags.
|
|
510
|
+
* Groups allow organizing commands and flags into logical sections in help output.
|
|
511
|
+
* Each group is defined as `[key, name]` where `key` is the identifier used in help options
|
|
512
|
+
* and `name` is the display name shown in help output.
|
|
513
|
+
*/
|
|
514
|
+
groups?: GroupsOptions;
|
|
515
|
+
}
|
|
516
|
+
declare const helpPlugin: ({
|
|
517
|
+
command,
|
|
518
|
+
flag,
|
|
519
|
+
showHelpWhenNoCommandSpecified,
|
|
520
|
+
notes,
|
|
521
|
+
examples,
|
|
522
|
+
banner,
|
|
523
|
+
formatters,
|
|
524
|
+
groups
|
|
525
|
+
}?: HelpPluginOptions) => Plugin$1;
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region ../plugin-not-found/src/index.d.ts
|
|
528
|
+
declare const notFoundPlugin: () => Plugin$1;
|
|
529
|
+
//#endregion
|
|
530
|
+
//#region ../plugin-strict-flags/src/index.d.ts
|
|
531
|
+
declare const strictFlagsPlugin: () => Plugin$1;
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region ../plugin-version/src/index.d.ts
|
|
534
|
+
interface VersionPluginOptions {
|
|
535
|
+
/**
|
|
536
|
+
* Whether to register the version command.
|
|
537
|
+
*
|
|
538
|
+
* @default true
|
|
539
|
+
*/
|
|
540
|
+
command?: boolean;
|
|
541
|
+
/**
|
|
542
|
+
* Whether to register the global version flag.
|
|
543
|
+
*
|
|
544
|
+
* @default true
|
|
545
|
+
*/
|
|
546
|
+
flag?: boolean;
|
|
547
|
+
}
|
|
548
|
+
declare const versionPlugin: ({
|
|
549
|
+
command,
|
|
550
|
+
flag
|
|
551
|
+
}?: VersionPluginOptions) => Plugin$1;
|
|
552
|
+
declare namespace re_exports_d_exports {
|
|
553
|
+
export { CommandHelpOptions, CompletionsPluginOptions, FriendlyErrorPluginOptions, GroupDefinition, GroupsOptions, HelpOptions, HelpPluginOptions, completionsPlugin, defaultFormatters, friendlyErrorPlugin, helpPlugin, notFoundPlugin, strictFlagsPlugin, versionPlugin };
|
|
554
|
+
}
|
|
555
|
+
import * as import___clerc_core from "@clerc/core";
|
|
556
|
+
declare namespace index_d_exports$1 {
|
|
557
|
+
export { Cli, CommandHelpOptions, CompletionsPluginOptions, FriendlyErrorPluginOptions, GroupDefinition, GroupsOptions, HelpOptions, HelpPluginOptions, completionsPlugin, defaultFormatters, friendlyErrorPlugin, helpPlugin, notFoundPlugin, strictFlagsPlugin, versionPlugin };
|
|
558
|
+
}
|
|
559
|
+
declare const Cli: (options?: CreateOptions$1) => Clerc$1;
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/utils.d.ts
|
|
562
|
+
declare const normalizeFlagValue: (flag: index_d_exports$1.ClercFlagDefinitionValue) => index_d_exports$1.ClercFlagOptions;
|
|
563
|
+
//#endregion
|
|
564
|
+
export { BaseContext, Clerc, ClercFlagDefinitionValue, ClercFlagOptions, ClercFlagsDefinition, 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, Parameter, ParameterDefinition, type ParseOptions, type index_d_exports as Parser, Plugin, flag_types_d_exports as Types, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, normalizeFlagValue, resolveCommand };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { t as __export } from "./chunk-
|
|
2
|
-
import { DOUBLE_DASH, DOUBLE_DASH as DOUBLE_DASH$1, Enum, InvalidSchemaError, KNOWN_FLAG, PARAMETER, PARAMETER as PARAMETER$1, UNKNOWN_FLAG, parse } from "@clerc/parser";
|
|
1
|
+
import { t as __export } from "./chunk-CYeTv9WL.js";
|
|
2
|
+
import { DOUBLE_DASH, DOUBLE_DASH as DOUBLE_DASH$1, Enum, InvalidSchemaError, KNOWN_FLAG, PARAMETER, PARAMETER as PARAMETER$1, Range, Regex, UNKNOWN_FLAG, parse } from "@clerc/parser";
|
|
3
3
|
import { LiteEmit } from "lite-emit";
|
|
4
4
|
|
|
5
5
|
//#region ../utils/src/index.ts
|
|
6
|
+
const looseIsArray = (arr) => Array.isArray(arr);
|
|
6
7
|
const toArray = (a) => Array.isArray(a) ? a : [a];
|
|
7
8
|
/**
|
|
8
9
|
* Converts a dash- or space-separated string to camelCase.
|
|
@@ -125,11 +126,10 @@ function _parseParameters(definitions, parameters) {
|
|
|
125
126
|
} else hasOptional = true;
|
|
126
127
|
const value = isVariadic ? parameters.slice(i) : parameters[i];
|
|
127
128
|
if (isRequired && (isVariadic ? value.length === 0 : value === void 0)) throw new InvalidParametersError(`Missing required ${isVariadic ? "variadic " : ""}parameter: ${name}`);
|
|
128
|
-
if (typeof definition !== "string" && definition.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
result[name] = value;
|
|
129
|
+
if (typeof definition !== "string" && definition.type) if (isVariadic) result[name] = value.map((v) => definition.type(v));
|
|
130
|
+
else if (value === void 0) result[name] = value;
|
|
131
|
+
else result[name] = definition.type(value);
|
|
132
|
+
else result[name] = value;
|
|
133
133
|
}
|
|
134
134
|
return result;
|
|
135
135
|
}
|
|
@@ -161,7 +161,7 @@ const platformArgv = IS_NODE ? process.argv.slice(IS_ELECTRON ? 1 : 2) : IS_DENO
|
|
|
161
161
|
var Clerc = class Clerc {
|
|
162
162
|
#argv = [];
|
|
163
163
|
#commands = /* @__PURE__ */ new Map();
|
|
164
|
-
#emitter = new LiteEmit(
|
|
164
|
+
#emitter = new LiteEmit();
|
|
165
165
|
#globalFlags = {};
|
|
166
166
|
#store = {};
|
|
167
167
|
#interceptors = [];
|
|
@@ -316,9 +316,9 @@ var Clerc = class Clerc {
|
|
|
316
316
|
};
|
|
317
317
|
const emitInterceptor = {
|
|
318
318
|
enforce: "post",
|
|
319
|
-
handler: (ctx) => {
|
|
319
|
+
handler: async (ctx) => {
|
|
320
320
|
if (parametersError) throw parametersError;
|
|
321
|
-
if (command) this.#emitter.emit(command.name, ctx);
|
|
321
|
+
if (command) await this.#emitter.emit(command.name, ctx);
|
|
322
322
|
else throw parametersToResolve.length > 0 ? new NoSuchCommandError(parametersToResolve.join(" ")) : new NoCommandSpecifiedError();
|
|
323
323
|
}
|
|
324
324
|
};
|
|
@@ -336,78 +336,12 @@ var Clerc = class Clerc {
|
|
|
336
336
|
};
|
|
337
337
|
|
|
338
338
|
//#endregion
|
|
339
|
-
//#region src/
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
Enum: () => Enum$1,
|
|
339
|
+
//#region src/flag-types.ts
|
|
340
|
+
var flag_types_exports = /* @__PURE__ */ __export({
|
|
341
|
+
Enum: () => Enum,
|
|
343
342
|
Range: () => Range,
|
|
344
343
|
Regex: () => Regex
|
|
345
344
|
});
|
|
346
|
-
/**
|
|
347
|
-
* Creates an enum constraint function that validates the input against a set of allowed values.
|
|
348
|
-
*
|
|
349
|
-
* @param values - Array of allowed string values
|
|
350
|
-
* @returns A ConstraintFunction that validates the input value
|
|
351
|
-
* @throws {Error} If the value is not in the allowed values list
|
|
352
|
-
*/
|
|
353
|
-
function Enum$1(...values) {
|
|
354
|
-
function fn(value) {
|
|
355
|
-
if (!values.includes(value)) throw new Error(`Invalid value: ${value}. Must be one of: ${values.join(", ")}`);
|
|
356
|
-
}
|
|
357
|
-
fn.display = values.join(" | ");
|
|
358
|
-
return fn;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Creates a range constraint function that validates the input is a number within the specified range.
|
|
362
|
-
*
|
|
363
|
-
* @param min - The minimum acceptable value (inclusive)
|
|
364
|
-
* @param max - The maximum acceptable value (inclusive)
|
|
365
|
-
* @returns A ConstraintFunction that validates the input value
|
|
366
|
-
* @throws {Error} If the value is not a number or is outside the specified range
|
|
367
|
-
*/
|
|
368
|
-
function Range(min, max) {
|
|
369
|
-
function fn(value) {
|
|
370
|
-
const num = Number(value);
|
|
371
|
-
if (Number.isNaN(num) || num < min || num > max) throw new Error(`Invalid value: ${value}. Must be a number between ${min} and ${max}`);
|
|
372
|
-
}
|
|
373
|
-
fn.display = `${min}-${max}`;
|
|
374
|
-
return fn;
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Creates a regex constraint function that validates the input against the provided pattern.
|
|
378
|
-
*
|
|
379
|
-
* @param pattern - The regular expression pattern to validate against
|
|
380
|
-
* @param description - Optional description for display purposes
|
|
381
|
-
* @returns A ConstraintFunction that validates the input value
|
|
382
|
-
* @throws {Error} If the value does not match the regex pattern
|
|
383
|
-
*/
|
|
384
|
-
function Regex(pattern, description) {
|
|
385
|
-
function fn(value) {
|
|
386
|
-
if (!pattern.test(value)) throw new Error(`Invalid value: ${value}. Must match pattern: ${pattern}`);
|
|
387
|
-
}
|
|
388
|
-
fn.display = description ?? pattern.toString();
|
|
389
|
-
return fn;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Just an utility to create custom constraints, helps you set the display name.
|
|
393
|
-
*
|
|
394
|
-
* @param validator - A function that validates the input value. Should return true if valid, false or throw an error if invalid.
|
|
395
|
-
* @param display - Optional display name for the constraint, useful in help output.
|
|
396
|
-
* @param errorMessage - Optional function to generate a custom error message when validation fails.
|
|
397
|
-
* @returns A ConstraintFunction that applies the custom validation logic.
|
|
398
|
-
* @throws {Error} If the validator returns false or throws an error.
|
|
399
|
-
*/
|
|
400
|
-
function Custom(validator, display, errorMessage) {
|
|
401
|
-
function fn(value) {
|
|
402
|
-
if (validator(value) === false) throw new Error(errorMessage ? errorMessage(value) : `Invalid value: ${value}`);
|
|
403
|
-
}
|
|
404
|
-
fn.display = display;
|
|
405
|
-
return fn;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
//#endregion
|
|
409
|
-
//#region src/flag-types.ts
|
|
410
|
-
var flag_types_exports = /* @__PURE__ */ __export({ Enum: () => Enum });
|
|
411
345
|
|
|
412
346
|
//#endregion
|
|
413
347
|
//#region src/helpers.ts
|
|
@@ -434,4 +368,8 @@ function createStopAtFirstParameter() {
|
|
|
434
368
|
const definePlugin = (plugin) => plugin;
|
|
435
369
|
|
|
436
370
|
//#endregion
|
|
437
|
-
|
|
371
|
+
//#region src/utils.ts
|
|
372
|
+
const normalizeFlagValue = (flag) => typeof flag === "function" || looseIsArray(flag) ? { type: flag } : flag;
|
|
373
|
+
|
|
374
|
+
//#endregion
|
|
375
|
+
export { Clerc, DOUBLE_DASH, InvalidCommandError, InvalidParametersError, InvalidSchemaError, KNOWN_FLAG, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, flag_types_exports as Types, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, normalizeFlagValue, resolveCommand };
|
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.19",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc core",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"lite-emit": "^
|
|
48
|
-
"@clerc/parser": "^1.0.0-beta.
|
|
47
|
+
"lite-emit": "^4.0.0",
|
|
48
|
+
"@clerc/parser": "^1.0.0-beta.19"
|
|
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.19"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/dist/chunk-BAz01cYq.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __export = (all, symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
__defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
if (symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { __export as t };
|