@clerc/core 1.0.0-beta.17 → 1.0.0-beta.18
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 +253 -85
- package/dist/index.js +15 -77
- package/package.json +3 -3
- 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,6 @@
|
|
|
1
|
+
import { n as __reExport, t as __export } from "./chunk-CYeTv9WL.js";
|
|
1
2
|
import { ErrorHandler as ErrorHandler$1 } from "lite-emit";
|
|
3
|
+
import { Clerc as Clerc$1, CreateOptions as CreateOptions$1, Plugin as Plugin$1 } from "@clerc/core";
|
|
2
4
|
|
|
3
5
|
//#region ../parser/src/errors.d.ts
|
|
4
6
|
declare class InvalidSchemaError extends Error {
|
|
@@ -8,23 +10,6 @@ declare class MissingRequiredFlagError extends Error {
|
|
|
8
10
|
constructor(name: string);
|
|
9
11
|
}
|
|
10
12
|
//#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
13
|
//#region ../utils/src/types/type-fest.d.ts
|
|
29
14
|
type LiteralUnion<LiteralType, BaseType> = LiteralType | (BaseType & Record<never, never>);
|
|
30
15
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
@@ -43,6 +28,11 @@ type PartialRequired<T, K$1 extends keyof T> = T & { [P in K$1]-?: T[P] };
|
|
|
43
28
|
type UnionToIntersection<U$1> = (U$1 extends any ? (k: U$1) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
44
29
|
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
30
|
//#endregion
|
|
31
|
+
//#region ../parser/src/iterator.d.ts
|
|
32
|
+
declare const KNOWN_FLAG = "known-flag";
|
|
33
|
+
declare const UNKNOWN_FLAG = "unknown-flag";
|
|
34
|
+
declare const PARAMETER = "parameter";
|
|
35
|
+
//#endregion
|
|
46
36
|
//#region ../parser/src/types.d.ts
|
|
47
37
|
interface FlagDefaultValueFunction<T> {
|
|
48
38
|
(): T;
|
|
@@ -172,10 +162,40 @@ type _InferFlags<T extends FlagsDefinition> = { [K in keyof T]: IsTypeAny<T[K]>
|
|
|
172
162
|
*/
|
|
173
163
|
type InferFlags<T extends FlagsDefinition> = Prettify<_InferFlags<T>>;
|
|
174
164
|
//#endregion
|
|
175
|
-
//#region ../parser/src/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
165
|
+
//#region ../parser/src/flag-types.d.ts
|
|
166
|
+
/**
|
|
167
|
+
* Creates a Enum type function that validates the input against allowed values.
|
|
168
|
+
* The display name will be formatted as "value1 | value2 | ..." for help output.
|
|
169
|
+
*
|
|
170
|
+
* @param values - Array of allowed string values
|
|
171
|
+
* @returns A FlagTypeFunction that validates and returns the input value
|
|
172
|
+
* @throws {Error} If the value is not in the allowed values list
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const format = Enum(['json', 'yaml', 'xml']);
|
|
177
|
+
* // Help output will show: json | yaml | xml
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare function Enum<T extends string>(...values: T[]): FlagTypeFunction<T>;
|
|
181
|
+
/**
|
|
182
|
+
* Creates a range type function that validates the input is a number within the specified range.
|
|
183
|
+
*
|
|
184
|
+
* @param min - The minimum acceptable value (inclusive)
|
|
185
|
+
* @param max - The maximum acceptable value (inclusive)
|
|
186
|
+
* @returns A FlagTypeFunction that validates the input value
|
|
187
|
+
* @throws {Error} If the value is not a number or is outside the specified range
|
|
188
|
+
*/
|
|
189
|
+
declare function Range(min: number, max: number): FlagTypeFunction<number>;
|
|
190
|
+
/**
|
|
191
|
+
* Creates a regex type function that validates the input against the provided pattern.
|
|
192
|
+
*
|
|
193
|
+
* @param pattern - The regular expression pattern to validate against
|
|
194
|
+
* @param description - Optional description for display purposes
|
|
195
|
+
* @returns A FlagTypeFunction that validates the input value
|
|
196
|
+
* @throws {Error} If the value does not match the regex pattern
|
|
197
|
+
*/
|
|
198
|
+
declare function Regex(pattern: RegExp, description?: string): FlagTypeFunction<string>;
|
|
179
199
|
//#endregion
|
|
180
200
|
//#region ../parser/src/parse.d.ts
|
|
181
201
|
declare const DOUBLE_DASH = "--";
|
|
@@ -185,7 +205,7 @@ declare function createParser<T extends FlagsDefinition>(options?: ParserOptions
|
|
|
185
205
|
};
|
|
186
206
|
declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
|
|
187
207
|
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 };
|
|
208
|
+
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
209
|
}
|
|
190
210
|
//#endregion
|
|
191
211
|
//#region src/types/clerc.d.ts
|
|
@@ -193,32 +213,20 @@ type ErrorHandler = (error: unknown) => void;
|
|
|
193
213
|
//#endregion
|
|
194
214
|
//#region src/types/flag.d.ts
|
|
195
215
|
interface FlagCustomOptions {}
|
|
196
|
-
type ClercFlagOptions = FlagOptions &
|
|
197
|
-
type ClercGlobalFlagDefinitionValue = ClercFlagOptions | FlagType;
|
|
198
|
-
type ClercFlagOptionsWithDescription = ClercFlagOptions & {
|
|
216
|
+
type ClercFlagOptions = FlagOptions & {
|
|
199
217
|
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
|
-
}
|
|
218
|
+
} & FlagCustomOptions;
|
|
219
|
+
type ClercFlagDefinitionValue = ClercFlagOptions | FlagType;
|
|
220
|
+
type ClercFlagsDefinition = Record<string, ClercFlagDefinitionValue>;
|
|
213
221
|
//#endregion
|
|
214
222
|
//#region src/types/parameters.d.ts
|
|
215
223
|
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["
|
|
224
|
+
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
225
|
type InferParameters<T extends readonly Parameter[]> = T extends readonly (infer U extends Parameter)[] ? Prettify<UnionToIntersection<InferParameter<U>>> : never;
|
|
218
226
|
interface ParameterDefinition {
|
|
219
227
|
key: string;
|
|
220
228
|
description?: string;
|
|
221
|
-
|
|
229
|
+
type?: FlagTypeFunction;
|
|
222
230
|
}
|
|
223
231
|
type Parameter = string | ParameterDefinition;
|
|
224
232
|
//#endregion
|
|
@@ -235,7 +243,7 @@ interface BaseContext<C extends Command = Command, GF extends ClercFlagsDefiniti
|
|
|
235
243
|
ignored: string[];
|
|
236
244
|
rawParsed: ParsedResult<InferFlagsWithGlobal<C, GF>>;
|
|
237
245
|
missingParameters: boolean;
|
|
238
|
-
store: ContextStore
|
|
246
|
+
store: Partial<ContextStore>;
|
|
239
247
|
}
|
|
240
248
|
//#endregion
|
|
241
249
|
//#region src/types/command.d.ts
|
|
@@ -303,7 +311,7 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
303
311
|
get _version(): string;
|
|
304
312
|
get _commands(): CommandsMap;
|
|
305
313
|
get _globalFlags(): GlobalFlags;
|
|
306
|
-
get store(): ContextStore
|
|
314
|
+
get store(): Partial<ContextStore>;
|
|
307
315
|
static create(options?: CreateOptions): Clerc;
|
|
308
316
|
name(name: string): this;
|
|
309
317
|
scriptName(scriptName: string): this;
|
|
@@ -314,8 +322,8 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
314
322
|
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
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, options?: CommandOptions<Parameters, Flags>): Clerc<Commands & Record<Name$1, Command<Name$1, Parameters, Flags>>, GlobalFlags>;
|
|
316
324
|
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
|
|
325
|
+
globalFlag<Name$1 extends string, Flag extends ClercFlagDefinitionValue>(name: Name$1, description: string, options: Flag): Clerc<Commands, GlobalFlags & Record<Name$1, Flag>>;
|
|
326
|
+
globalFlag<Name$1 extends string, Flag extends ClercFlagDefinitionValue>(name: Name$1, options: Flag): Clerc<Commands, GlobalFlags & Record<Name$1, Flag>>;
|
|
319
327
|
interceptor(interceptor: Interceptor<Command, GlobalFlags>): this;
|
|
320
328
|
on<Name$1 extends LiteralUnion<keyof Commands, string>>(name: Name$1, handler: CommandHandler<Commands[Name$1], GlobalFlags>): this;
|
|
321
329
|
run(): Promise<void>;
|
|
@@ -324,45 +332,6 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
324
332
|
//#endregion
|
|
325
333
|
//#region src/commands.d.ts
|
|
326
334
|
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
335
|
//#endregion
|
|
367
336
|
//#region src/errors.d.ts
|
|
368
337
|
declare class NoSuchCommandError extends Error {
|
|
@@ -382,7 +351,7 @@ declare class InvalidParametersError extends Error {
|
|
|
382
351
|
constructor(message: string);
|
|
383
352
|
}
|
|
384
353
|
declare namespace flag_types_d_exports {
|
|
385
|
-
export { Enum };
|
|
354
|
+
export { Enum, Range, Regex };
|
|
386
355
|
}
|
|
387
356
|
//#endregion
|
|
388
357
|
//#region src/helpers.d.ts
|
|
@@ -394,4 +363,203 @@ declare function createStopAtFirstParameter(): IgnoreFunction;
|
|
|
394
363
|
//#region src/plugin.d.ts
|
|
395
364
|
declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
396
365
|
//#endregion
|
|
397
|
-
|
|
366
|
+
//#region ../plugin-completions/src/index.d.ts
|
|
367
|
+
declare module "@clerc/core" {
|
|
368
|
+
interface CommandCustomOptions {
|
|
369
|
+
/**
|
|
370
|
+
* Completions options for the command.
|
|
371
|
+
*/
|
|
372
|
+
completions?: {
|
|
373
|
+
/**
|
|
374
|
+
* Whether to show the command in completions output.
|
|
375
|
+
*
|
|
376
|
+
* @default true
|
|
377
|
+
*/
|
|
378
|
+
show?: boolean;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
interface CompletionsPluginOptions {
|
|
383
|
+
/**
|
|
384
|
+
* Whether to register the `completions install` and `completions uninstall` commands.
|
|
385
|
+
* @default true
|
|
386
|
+
*/
|
|
387
|
+
managementCommands?: boolean;
|
|
388
|
+
}
|
|
389
|
+
declare const completionsPlugin: (options?: CompletionsPluginOptions) => Plugin$1;
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region ../plugin-friendly-error/src/index.d.ts
|
|
392
|
+
interface FriendlyErrorPluginOptions {
|
|
393
|
+
target?: (str: string) => void;
|
|
394
|
+
}
|
|
395
|
+
declare const friendlyErrorPlugin: ({
|
|
396
|
+
target
|
|
397
|
+
}?: FriendlyErrorPluginOptions) => Plugin$1;
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region ../plugin-help/src/types.d.ts
|
|
400
|
+
interface Formatters {
|
|
401
|
+
formatFlagType: (type: FlagType) => string;
|
|
402
|
+
formatFlagDefault: <T>(value: FlagDefaultValue<T>) => string;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* A group definition as a tuple of [key, displayName].
|
|
406
|
+
* The key is used in help options to assign items to groups.
|
|
407
|
+
* The displayName is shown in the help output.
|
|
408
|
+
*/
|
|
409
|
+
type GroupDefinition = [key: string, name: string];
|
|
410
|
+
/**
|
|
411
|
+
* Options for defining groups in help output.
|
|
412
|
+
*/
|
|
413
|
+
interface GroupsOptions {
|
|
414
|
+
/**
|
|
415
|
+
* Groups for commands.
|
|
416
|
+
* Each group is defined as `[key, name]`.
|
|
417
|
+
*/
|
|
418
|
+
commands?: GroupDefinition[];
|
|
419
|
+
/**
|
|
420
|
+
* Groups for command-specific flags.
|
|
421
|
+
* Each group is defined as `[key, name]`.
|
|
422
|
+
*/
|
|
423
|
+
flags?: GroupDefinition[];
|
|
424
|
+
/**
|
|
425
|
+
* Groups for global flags.
|
|
426
|
+
* Each group is defined as `[key, name]`.
|
|
427
|
+
*/
|
|
428
|
+
globalFlags?: GroupDefinition[];
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region ../plugin-help/src/formatters.d.ts
|
|
432
|
+
declare const defaultFormatters: Formatters;
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region ../plugin-help/src/index.d.ts
|
|
435
|
+
interface HelpOptions {
|
|
436
|
+
/**
|
|
437
|
+
* The group this item belongs to.
|
|
438
|
+
* The group must be defined in the `groups` option of `helpPlugin()`.
|
|
439
|
+
*/
|
|
440
|
+
group?: string;
|
|
441
|
+
}
|
|
442
|
+
interface CommandHelpOptions extends HelpOptions {
|
|
443
|
+
/**
|
|
444
|
+
* Whether to show the command in help output.
|
|
445
|
+
*
|
|
446
|
+
* @default true
|
|
447
|
+
*/
|
|
448
|
+
show?: boolean;
|
|
449
|
+
/**
|
|
450
|
+
* Notes to show in the help output.
|
|
451
|
+
*/
|
|
452
|
+
notes?: string[];
|
|
453
|
+
/**
|
|
454
|
+
* Examples to show in the help output.
|
|
455
|
+
* Each example is a tuple of `[command, description]`.
|
|
456
|
+
*/
|
|
457
|
+
examples?: [string, string][];
|
|
458
|
+
}
|
|
459
|
+
declare module "@clerc/core" {
|
|
460
|
+
interface CommandCustomOptions {
|
|
461
|
+
/**
|
|
462
|
+
* Help options for the command.
|
|
463
|
+
*/
|
|
464
|
+
help?: CommandHelpOptions;
|
|
465
|
+
}
|
|
466
|
+
interface FlagCustomOptions {
|
|
467
|
+
/**
|
|
468
|
+
* Help options for the flag.
|
|
469
|
+
*/
|
|
470
|
+
help?: HelpOptions;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
interface HelpPluginOptions {
|
|
474
|
+
/**
|
|
475
|
+
* Whether to register the `help` command.
|
|
476
|
+
*
|
|
477
|
+
* @default true
|
|
478
|
+
*/
|
|
479
|
+
command?: boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Whether to register the `--help` global flag.
|
|
482
|
+
*
|
|
483
|
+
* @default true
|
|
484
|
+
*/
|
|
485
|
+
flag?: boolean;
|
|
486
|
+
/**
|
|
487
|
+
* Whether to show help when no command is specified.
|
|
488
|
+
*
|
|
489
|
+
* @default true
|
|
490
|
+
*/
|
|
491
|
+
showHelpWhenNoCommandSpecified?: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* Notes to show in the help output.
|
|
494
|
+
*/
|
|
495
|
+
notes?: string[];
|
|
496
|
+
/**
|
|
497
|
+
* Examples to show in the help output.
|
|
498
|
+
* Each example is a tuple of `[command, description]`.
|
|
499
|
+
*/
|
|
500
|
+
examples?: [string, string][];
|
|
501
|
+
/**
|
|
502
|
+
* A banner to show before the help output.
|
|
503
|
+
*/
|
|
504
|
+
banner?: string;
|
|
505
|
+
/**
|
|
506
|
+
* Custom formatters for rendering help.
|
|
507
|
+
*/
|
|
508
|
+
formatters?: Partial<Formatters>;
|
|
509
|
+
/**
|
|
510
|
+
* Group definitions for commands and flags.
|
|
511
|
+
* Groups allow organizing commands and flags into logical sections in help output.
|
|
512
|
+
* Each group is defined as `[key, name]` where `key` is the identifier used in help options
|
|
513
|
+
* and `name` is the display name shown in help output.
|
|
514
|
+
*/
|
|
515
|
+
groups?: GroupsOptions;
|
|
516
|
+
}
|
|
517
|
+
declare const helpPlugin: ({
|
|
518
|
+
command,
|
|
519
|
+
flag,
|
|
520
|
+
showHelpWhenNoCommandSpecified,
|
|
521
|
+
notes,
|
|
522
|
+
examples,
|
|
523
|
+
banner,
|
|
524
|
+
formatters,
|
|
525
|
+
groups
|
|
526
|
+
}?: HelpPluginOptions) => Plugin$1;
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region ../plugin-not-found/src/index.d.ts
|
|
529
|
+
declare const notFoundPlugin: () => Plugin$1;
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region ../plugin-strict-flags/src/index.d.ts
|
|
532
|
+
declare const strictFlagsPlugin: () => Plugin$1;
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region ../plugin-version/src/index.d.ts
|
|
535
|
+
interface VersionPluginOptions {
|
|
536
|
+
/**
|
|
537
|
+
* Whether to register the version command.
|
|
538
|
+
*
|
|
539
|
+
* @default true
|
|
540
|
+
*/
|
|
541
|
+
command?: boolean;
|
|
542
|
+
/**
|
|
543
|
+
* Whether to register the global version flag.
|
|
544
|
+
*
|
|
545
|
+
* @default true
|
|
546
|
+
*/
|
|
547
|
+
flag?: boolean;
|
|
548
|
+
}
|
|
549
|
+
declare const versionPlugin: ({
|
|
550
|
+
command,
|
|
551
|
+
flag
|
|
552
|
+
}?: VersionPluginOptions) => Plugin$1;
|
|
553
|
+
declare namespace re_exports_d_exports {
|
|
554
|
+
export { CommandHelpOptions, CompletionsPluginOptions, FriendlyErrorPluginOptions, GroupDefinition, GroupsOptions, HelpOptions, HelpPluginOptions, completionsPlugin, defaultFormatters, friendlyErrorPlugin, helpPlugin, notFoundPlugin, strictFlagsPlugin, versionPlugin };
|
|
555
|
+
}
|
|
556
|
+
import * as import___clerc_core from "@clerc/core";
|
|
557
|
+
declare namespace index_d_exports$1 {
|
|
558
|
+
export { Cli, CommandHelpOptions, CompletionsPluginOptions, FriendlyErrorPluginOptions, GroupDefinition, GroupsOptions, HelpOptions, HelpPluginOptions, completionsPlugin, defaultFormatters, friendlyErrorPlugin, helpPlugin, notFoundPlugin, strictFlagsPlugin, versionPlugin };
|
|
559
|
+
}
|
|
560
|
+
declare const Cli: (options?: CreateOptions$1) => Clerc$1;
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/utils.d.ts
|
|
563
|
+
declare const normalizeFlagValue: (flag: index_d_exports$1.ClercFlagDefinitionValue) => index_d_exports$1.ClercFlagOptions;
|
|
564
|
+
//#endregion
|
|
565
|
+
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
|
}
|
|
@@ -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.18",
|
|
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.18"
|
|
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.18"
|
|
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 };
|