@clerc/core 1.0.0-beta.28 → 1.0.0-beta.29
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 +50 -239
- package/dist/index.js +32 -42
- package/package.json +4 -3
- package/dist/chunk-CYeTv9WL.js +0 -42
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Clerc as Clerc$1, CreateOptions as CreateOptions$1, Plugin as Plugin$1 } from "@clerc/core";
|
|
3
|
-
|
|
1
|
+
//#endregion
|
|
4
2
|
//#region ../parser/src/errors.d.ts
|
|
5
3
|
declare class InvalidSchemaError extends Error {
|
|
6
4
|
constructor(message: string);
|
|
@@ -25,11 +23,6 @@ type PartialRequired<T, K$1 extends keyof T> = T & { [P in K$1]-?: T[P] };
|
|
|
25
23
|
type UnionToIntersection<U$1> = (U$1 extends any ? (k: U$1) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
26
24
|
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;
|
|
27
25
|
//#endregion
|
|
28
|
-
//#region ../parser/src/iterator.d.ts
|
|
29
|
-
declare const KNOWN_FLAG = "known-flag";
|
|
30
|
-
declare const UNKNOWN_FLAG = "unknown-flag";
|
|
31
|
-
declare const PARAMETER = "parameter";
|
|
32
|
-
//#endregion
|
|
33
26
|
//#region ../parser/src/types.d.ts
|
|
34
27
|
interface FlagDefaultValueFunction<T> {
|
|
35
28
|
(): T;
|
|
@@ -163,7 +156,27 @@ type _InferFlags<T extends FlagsDefinition> = { [K in keyof T]: IsTypeAny<T[K]>
|
|
|
163
156
|
*/
|
|
164
157
|
type InferFlags<T extends FlagsDefinition> = Prettify<_InferFlags<T>>;
|
|
165
158
|
//#endregion
|
|
166
|
-
//#region ../parser/src/
|
|
159
|
+
//#region ../parser/src/iterator.d.ts
|
|
160
|
+
declare const KNOWN_FLAG = "known-flag";
|
|
161
|
+
declare const UNKNOWN_FLAG = "unknown-flag";
|
|
162
|
+
declare const PARAMETER = "parameter";
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region ../parser/src/parse.d.ts
|
|
165
|
+
declare const DOUBLE_DASH = "--";
|
|
166
|
+
type ParseFunction<T extends FlagsDefinition> = (args: string[]) => ParsedResult<InferFlags<T>>;
|
|
167
|
+
declare function createParser<T extends FlagsDefinition>(options?: ParserOptions<T>): {
|
|
168
|
+
parse: ParseFunction<T>;
|
|
169
|
+
};
|
|
170
|
+
declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
|
|
171
|
+
declare namespace index_d_exports {
|
|
172
|
+
export { BaseFlagOptions, DOUBLE_DASH, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, RawInputType, TypeFunction, TypeValue, UNKNOWN_FLAG, createParser, parse };
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region ../advanced-types/src/errors.d.ts
|
|
176
|
+
declare class FlagValidationError extends Error {}
|
|
177
|
+
declare namespace index_d_exports$1 {
|
|
178
|
+
export { Enum, FlagValidationError, Range, Regex };
|
|
179
|
+
}
|
|
167
180
|
/**
|
|
168
181
|
* Creates a Enum type function that validates the input against allowed values.
|
|
169
182
|
* The display name will be formatted as "value1 | value2 | ..." for help output.
|
|
@@ -198,17 +211,6 @@ declare function Range(min: number, max: number): TypeFunction<number>;
|
|
|
198
211
|
*/
|
|
199
212
|
declare function Regex(pattern: RegExp, description?: string): TypeFunction<string>;
|
|
200
213
|
//#endregion
|
|
201
|
-
//#region ../parser/src/parse.d.ts
|
|
202
|
-
declare const DOUBLE_DASH = "--";
|
|
203
|
-
type ParseFunction<T extends FlagsDefinition> = (args: string[]) => ParsedResult<InferFlags<T>>;
|
|
204
|
-
declare function createParser<T extends FlagsDefinition>(options?: ParserOptions<T>): {
|
|
205
|
-
parse: ParseFunction<T>;
|
|
206
|
-
};
|
|
207
|
-
declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
|
|
208
|
-
declare namespace index_d_exports {
|
|
209
|
-
export { BaseFlagOptions, DOUBLE_DASH, Enum, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, Range, RawInputType, Regex, TypeFunction, TypeValue, UNKNOWN_FLAG, createParser, parse };
|
|
210
|
-
}
|
|
211
|
-
//#endregion
|
|
212
214
|
//#region src/types/clerc.d.ts
|
|
213
215
|
type ErrorHandler = (error: unknown) => void;
|
|
214
216
|
//#endregion
|
|
@@ -220,16 +222,17 @@ type ClercFlagOptions = FlagOptions & {
|
|
|
220
222
|
type ClercFlagDefinitionValue = ClercFlagOptions | TypeValue;
|
|
221
223
|
type ClercFlagsDefinition = Record<string, ClercFlagDefinitionValue>;
|
|
222
224
|
//#endregion
|
|
223
|
-
//#region src/types/
|
|
225
|
+
//#region src/types/parameter.d.ts
|
|
226
|
+
interface ParameterCustomOptions {}
|
|
224
227
|
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;
|
|
225
|
-
type InferParameter<T extends
|
|
226
|
-
type InferParameters<T extends readonly
|
|
227
|
-
|
|
228
|
+
type InferParameter<T extends ParameterDefinitionValue> = T extends string ? InferStringParameter<T> : T extends ParameterOptions ? T["type"] extends TypeFunction<infer U> ? InferStringParameter<T["key"], U> : InferStringParameter<T["key"]> : never;
|
|
229
|
+
type InferParameters<T extends readonly ParameterDefinitionValue[]> = T extends readonly (infer U extends ParameterDefinitionValue)[] ? Prettify<UnionToIntersection<InferParameter<U>>> : never;
|
|
230
|
+
type ParameterOptions = {
|
|
228
231
|
key: string;
|
|
229
232
|
description?: string;
|
|
230
233
|
type?: TypeFunction;
|
|
231
|
-
}
|
|
232
|
-
type
|
|
234
|
+
} & ParameterCustomOptions;
|
|
235
|
+
type ParameterDefinitionValue = string | ParameterOptions;
|
|
233
236
|
//#endregion
|
|
234
237
|
//#region src/types/context.d.ts
|
|
235
238
|
type AddStringIndex<T> = T & Record<string, any>;
|
|
@@ -248,7 +251,7 @@ interface BaseContext<C extends Command = Command, GF extends ClercFlagsDefiniti
|
|
|
248
251
|
//#endregion
|
|
249
252
|
//#region src/types/command.d.ts
|
|
250
253
|
interface CommandCustomOptions {}
|
|
251
|
-
interface CommandOptions<Parameters extends readonly
|
|
254
|
+
interface CommandOptions<Parameters extends readonly ParameterDefinitionValue[] = readonly ParameterDefinitionValue[], Flags extends ClercFlagsDefinition = ClercFlagsDefinition> extends CommandCustomOptions {
|
|
252
255
|
alias?: MaybeArray<string>;
|
|
253
256
|
parameters?: Parameters;
|
|
254
257
|
flags?: Flags;
|
|
@@ -257,11 +260,11 @@ interface CommandOptions<Parameters extends readonly Parameter[] = readonly Para
|
|
|
257
260
|
*/
|
|
258
261
|
ignore?: IgnoreFunction;
|
|
259
262
|
}
|
|
260
|
-
interface Command<Name$1 extends string = string, Parameters extends readonly
|
|
263
|
+
interface Command<Name$1 extends string = string, Parameters extends readonly ParameterDefinitionValue[] = readonly ParameterDefinitionValue[], Flags extends ClercFlagsDefinition = ClercFlagsDefinition> extends CommandOptions<Parameters, Flags> {
|
|
261
264
|
name: Name$1;
|
|
262
265
|
description?: string;
|
|
263
266
|
}
|
|
264
|
-
type CommandWithHandler<Name$1 extends string = string, Parameters extends readonly
|
|
267
|
+
type CommandWithHandler<Name$1 extends string = string, Parameters extends readonly ParameterDefinitionValue[] = readonly ParameterDefinitionValue[], Flags extends ClercFlagsDefinition = ClercFlagsDefinition> = Command<Name$1, Parameters, Flags> & {
|
|
265
268
|
handler?: CommandHandler<Command<Name$1, Parameters, Flags>>;
|
|
266
269
|
};
|
|
267
270
|
type CommandsRecord = Record<string, Command>;
|
|
@@ -319,9 +322,9 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
319
322
|
version(version: string): this;
|
|
320
323
|
use(plugin: Plugin): this;
|
|
321
324
|
errorHandler(handler: ErrorHandler): this;
|
|
322
|
-
command<Name$1 extends string, const Parameters extends readonly
|
|
323
|
-
command<Name$1 extends string, const Parameters extends readonly
|
|
324
|
-
command<Name$1 extends string, const Parameters extends readonly
|
|
325
|
+
command<Name$1 extends string, const Parameters extends readonly ParameterDefinitionValue[], Flags extends ClercFlagsDefinition>(command: CommandWithHandler<Name$1, Parameters, Flags>): Clerc<Commands & Record<string, CommandWithHandler<Name$1, Parameters, Flags>>, GlobalFlags>;
|
|
326
|
+
command<Name$1 extends string, const Parameters extends readonly ParameterDefinitionValue[], 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>;
|
|
327
|
+
command<Name$1 extends string, const Parameters extends readonly ParameterDefinitionValue[], 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>;
|
|
325
328
|
globalFlag<Name$1 extends string, Flag extends ClercFlagDefinitionValue>(name: Name$1, description: string, options: Flag): Clerc<Commands, GlobalFlags & Record<Name$1, Flag>>;
|
|
326
329
|
globalFlag<Name$1 extends string, Flag extends ClercFlagDefinitionValue>(name: Name$1, options: Flag): Clerc<Commands, GlobalFlags & Record<Name$1, Flag>>;
|
|
327
330
|
interceptor(interceptor: Interceptor<Command, GlobalFlags>): this;
|
|
@@ -330,7 +333,7 @@ declare class Clerc<Commands extends CommandsRecord = {}, GlobalFlags extends Cl
|
|
|
330
333
|
parse<Run extends boolean = true>(argvOrOptions?: string[] | ParseOptions<Run>): Run extends true ? Promise<void> : this;
|
|
331
334
|
}
|
|
332
335
|
//#endregion
|
|
333
|
-
//#region src/
|
|
336
|
+
//#region src/command.d.ts
|
|
334
337
|
declare function resolveCommand(commandsMap: CommandsMap, parameters: string[]): [Command, string] | [undefined, undefined];
|
|
335
338
|
//#endregion
|
|
336
339
|
//#region src/errors.d.ts
|
|
@@ -341,226 +344,34 @@ declare class NoSuchCommandError extends Error {
|
|
|
341
344
|
declare class NoCommandSpecifiedError extends Error {
|
|
342
345
|
constructor(text?: string);
|
|
343
346
|
}
|
|
344
|
-
declare class InvalidCommandError extends Error {
|
|
345
|
-
constructor(message: string);
|
|
346
|
-
}
|
|
347
|
+
declare class InvalidCommandError extends Error {}
|
|
347
348
|
declare class MissingRequiredMetadataError extends Error {
|
|
348
349
|
constructor(metadataName: string);
|
|
349
350
|
}
|
|
350
|
-
declare class InvalidParametersError extends Error {
|
|
351
|
-
constructor(message: string);
|
|
352
|
-
}
|
|
351
|
+
declare class InvalidParametersError extends Error {}
|
|
353
352
|
declare class MissingRequiredFlagError extends Error {
|
|
354
353
|
constructor(flags: string[]);
|
|
355
354
|
}
|
|
356
|
-
declare namespace flag_types_d_exports {
|
|
357
|
-
export { Enum, Range, Regex };
|
|
358
|
-
}
|
|
359
355
|
//#endregion
|
|
360
356
|
//#region src/helpers.d.ts
|
|
361
|
-
declare const defineCommand: <Name$1 extends string, const Parameters extends readonly
|
|
357
|
+
declare const defineCommand: <Name$1 extends string, const Parameters extends readonly ParameterDefinitionValue[], Flags extends ClercFlagsDefinition>(command: Command<Name$1, Parameters, Flags>, handler?: NoInfer<CommandHandler<Command<Name$1, Parameters, Flags>>>) => CommandWithHandler<Name$1, Parameters, Flags>;
|
|
362
358
|
//#endregion
|
|
363
359
|
//#region src/ignore.d.ts
|
|
364
360
|
declare function createStopAtFirstParameter(): IgnoreFunction;
|
|
365
361
|
//#endregion
|
|
366
|
-
//#region src/
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
interface CommandCustomOptions {
|
|
372
|
-
/**
|
|
373
|
-
* Completions options for the command.
|
|
374
|
-
*/
|
|
375
|
-
completions?: {
|
|
376
|
-
/**
|
|
377
|
-
* Whether to show the command in completions output.
|
|
378
|
-
*
|
|
379
|
-
* @default true
|
|
380
|
-
*/
|
|
381
|
-
show?: boolean;
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
declare const completionsPlugin: () => Plugin$1;
|
|
386
|
-
//#endregion
|
|
387
|
-
//#region ../plugin-friendly-error/src/index.d.ts
|
|
388
|
-
interface FriendlyErrorPluginOptions {
|
|
389
|
-
target?: (str: string) => void;
|
|
390
|
-
}
|
|
391
|
-
declare const friendlyErrorPlugin: ({
|
|
392
|
-
target
|
|
393
|
-
}?: FriendlyErrorPluginOptions) => Plugin$1;
|
|
394
|
-
//#endregion
|
|
395
|
-
//#region ../plugin-help/src/types.d.ts
|
|
396
|
-
interface Formatters {
|
|
397
|
-
formatTypeValue: (type: TypeValue) => string;
|
|
398
|
-
formatFlagDefault: <T>(value: FlagDefaultValue<T>) => string;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* A group definition as a tuple of [key, displayName].
|
|
402
|
-
* The key is used in help options to assign items to groups.
|
|
403
|
-
* The displayName is shown in the help output.
|
|
404
|
-
*/
|
|
405
|
-
type GroupDefinition = [key: string, name: string];
|
|
406
|
-
/**
|
|
407
|
-
* Options for defining groups in help output.
|
|
408
|
-
*/
|
|
409
|
-
interface GroupsOptions {
|
|
410
|
-
/**
|
|
411
|
-
* Groups for commands.
|
|
412
|
-
* Each group is defined as `[key, name]`.
|
|
413
|
-
*/
|
|
414
|
-
commands?: GroupDefinition[];
|
|
415
|
-
/**
|
|
416
|
-
* Groups for command-specific flags.
|
|
417
|
-
* Each group is defined as `[key, name]`.
|
|
418
|
-
*/
|
|
419
|
-
flags?: GroupDefinition[];
|
|
420
|
-
/**
|
|
421
|
-
* Groups for global flags.
|
|
422
|
-
* Each group is defined as `[key, name]`.
|
|
423
|
-
*/
|
|
424
|
-
globalFlags?: GroupDefinition[];
|
|
362
|
+
//#region src/parameter.d.ts
|
|
363
|
+
interface ParameterInfo {
|
|
364
|
+
name: string;
|
|
365
|
+
isRequired: boolean;
|
|
366
|
+
isVariadic: boolean;
|
|
425
367
|
}
|
|
368
|
+
declare function extractParameterInfo(key: string): ParameterInfo;
|
|
426
369
|
//#endregion
|
|
427
|
-
//#region
|
|
428
|
-
declare const
|
|
429
|
-
//#endregion
|
|
430
|
-
//#region ../plugin-help/src/index.d.ts
|
|
431
|
-
interface HelpOptions {
|
|
432
|
-
/**
|
|
433
|
-
* The group this item belongs to.
|
|
434
|
-
* The group must be defined in the `groups` option of `helpPlugin()`.
|
|
435
|
-
*/
|
|
436
|
-
group?: string;
|
|
437
|
-
}
|
|
438
|
-
interface CommandHelpOptions extends HelpOptions {
|
|
439
|
-
/**
|
|
440
|
-
* Whether to show the command in help output.
|
|
441
|
-
*
|
|
442
|
-
* @default true
|
|
443
|
-
*/
|
|
444
|
-
show?: boolean;
|
|
445
|
-
/**
|
|
446
|
-
* Notes to show in the help output.
|
|
447
|
-
*/
|
|
448
|
-
notes?: string[];
|
|
449
|
-
/**
|
|
450
|
-
* Examples to show in the help output.
|
|
451
|
-
* Each example is a tuple of `[command, description]`.
|
|
452
|
-
*/
|
|
453
|
-
examples?: [string, string][];
|
|
454
|
-
}
|
|
455
|
-
declare module "@clerc/core" {
|
|
456
|
-
interface CommandCustomOptions {
|
|
457
|
-
/**
|
|
458
|
-
* Help options for the command.
|
|
459
|
-
*/
|
|
460
|
-
help?: CommandHelpOptions;
|
|
461
|
-
}
|
|
462
|
-
interface FlagCustomOptions {
|
|
463
|
-
/**
|
|
464
|
-
* Help options for the flag.
|
|
465
|
-
*/
|
|
466
|
-
help?: HelpOptions;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
interface HelpPluginOptions {
|
|
470
|
-
/**
|
|
471
|
-
* Whether to register the `help` command.
|
|
472
|
-
*
|
|
473
|
-
* @default true
|
|
474
|
-
*/
|
|
475
|
-
command?: boolean;
|
|
476
|
-
/**
|
|
477
|
-
* Whether to register the `--help` global flag.
|
|
478
|
-
*
|
|
479
|
-
* @default true
|
|
480
|
-
*/
|
|
481
|
-
flag?: boolean;
|
|
482
|
-
/**
|
|
483
|
-
* Whether to show help when no command is specified.
|
|
484
|
-
*
|
|
485
|
-
* @default true
|
|
486
|
-
*/
|
|
487
|
-
showHelpWhenNoCommandSpecified?: boolean;
|
|
488
|
-
/**
|
|
489
|
-
* Notes to show in the help output.
|
|
490
|
-
*/
|
|
491
|
-
notes?: string[];
|
|
492
|
-
/**
|
|
493
|
-
* Examples to show in the help output.
|
|
494
|
-
* Each example is a tuple of `[command, description]`.
|
|
495
|
-
*/
|
|
496
|
-
examples?: [string, string][];
|
|
497
|
-
/**
|
|
498
|
-
* Header to show before the help output.
|
|
499
|
-
*/
|
|
500
|
-
header?: string;
|
|
501
|
-
/**
|
|
502
|
-
* Footer to show after the help output.
|
|
503
|
-
*/
|
|
504
|
-
footer?: 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
|
-
header,
|
|
524
|
-
footer,
|
|
525
|
-
formatters,
|
|
526
|
-
groups
|
|
527
|
-
}?: HelpPluginOptions) => Plugin$1;
|
|
528
|
-
//#endregion
|
|
529
|
-
//#region ../plugin-not-found/src/index.d.ts
|
|
530
|
-
declare const notFoundPlugin: () => Plugin$1;
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region ../plugin-strict-flags/src/index.d.ts
|
|
533
|
-
declare const strictFlagsPlugin: () => Plugin$1;
|
|
534
|
-
//#endregion
|
|
535
|
-
//#region ../plugin-version/src/index.d.ts
|
|
536
|
-
interface VersionPluginOptions {
|
|
537
|
-
/**
|
|
538
|
-
* Whether to register the version command.
|
|
539
|
-
*
|
|
540
|
-
* @default true
|
|
541
|
-
*/
|
|
542
|
-
command?: boolean;
|
|
543
|
-
/**
|
|
544
|
-
* Whether to register the global version flag.
|
|
545
|
-
*
|
|
546
|
-
* @default true
|
|
547
|
-
*/
|
|
548
|
-
flag?: boolean;
|
|
549
|
-
}
|
|
550
|
-
declare const versionPlugin: ({
|
|
551
|
-
command,
|
|
552
|
-
flag
|
|
553
|
-
}?: VersionPluginOptions) => Plugin$1;
|
|
554
|
-
declare namespace re_exports_d_exports {
|
|
555
|
-
export { CommandHelpOptions, FriendlyErrorPluginOptions, GroupDefinition, GroupsOptions, HelpOptions, HelpPluginOptions, completionsPlugin, defaultFormatters, friendlyErrorPlugin, helpPlugin, notFoundPlugin, strictFlagsPlugin, versionPlugin };
|
|
556
|
-
}
|
|
557
|
-
import * as import___clerc_core from "@clerc/core";
|
|
558
|
-
declare namespace index_d_exports$1 {
|
|
559
|
-
export { Cli, CommandHelpOptions, FriendlyErrorPluginOptions, GroupDefinition, GroupsOptions, HelpOptions, HelpPluginOptions, completionsPlugin, defaultFormatters, friendlyErrorPlugin, helpPlugin, notFoundPlugin, strictFlagsPlugin, versionPlugin };
|
|
560
|
-
}
|
|
561
|
-
declare const Cli: (options?: CreateOptions$1) => Clerc$1;
|
|
370
|
+
//#region src/plugin.d.ts
|
|
371
|
+
declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
562
372
|
//#endregion
|
|
563
373
|
//#region src/utils.d.ts
|
|
564
|
-
declare const normalizeFlagValue: (flag:
|
|
374
|
+
declare const normalizeFlagValue: (flag: ClercFlagDefinitionValue) => ClercFlagOptions;
|
|
375
|
+
declare const normalizeParameterValue: (parameter: ParameterDefinitionValue) => ParameterOptions;
|
|
565
376
|
//#endregion
|
|
566
|
-
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, MissingRequiredFlagError, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER,
|
|
377
|
+
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, MissingRequiredFlagError, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, ParameterCustomOptions, ParameterDefinitionValue, ParameterOptions, type ParseOptions, type index_d_exports as Parser, Plugin, index_d_exports$1 as Types, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, extractParameterInfo, normalizeFlagValue, normalizeParameterValue, resolveCommand };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DOUBLE_DASH, DOUBLE_DASH as DOUBLE_DASH$1,
|
|
1
|
+
import * as Types from "@clerc/advanced-types";
|
|
2
|
+
import { DOUBLE_DASH, DOUBLE_DASH as DOUBLE_DASH$1, InvalidSchemaError, KNOWN_FLAG, PARAMETER, PARAMETER as PARAMETER$1, UNKNOWN_FLAG, parse } from "@clerc/parser";
|
|
3
3
|
import { LiteEmit } from "lite-emit";
|
|
4
4
|
|
|
5
5
|
//#region ../utils/src/index.ts
|
|
@@ -27,7 +27,7 @@ function camelCase(str) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
|
-
//#region src/
|
|
30
|
+
//#region src/command.ts
|
|
31
31
|
function resolveCommand(commandsMap, parameters) {
|
|
32
32
|
for (let i = parameters.length; i >= 0; i--) {
|
|
33
33
|
const name = parameters.slice(0, i).join(" ");
|
|
@@ -49,21 +49,13 @@ var NoCommandSpecifiedError = class extends Error {
|
|
|
49
49
|
super(text);
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
var InvalidCommandError = class extends Error {
|
|
53
|
-
constructor(message) {
|
|
54
|
-
super(message);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
52
|
+
var InvalidCommandError = class extends Error {};
|
|
57
53
|
var MissingRequiredMetadataError = class extends Error {
|
|
58
54
|
constructor(metadataName) {
|
|
59
55
|
super(`CLI ${metadataName} is required.`);
|
|
60
56
|
}
|
|
61
57
|
};
|
|
62
|
-
var InvalidParametersError = class extends Error {
|
|
63
|
-
constructor(message) {
|
|
64
|
-
super(message);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
58
|
+
var InvalidParametersError = class extends Error {};
|
|
67
59
|
var MissingRequiredFlagError = class extends Error {
|
|
68
60
|
constructor(flags) {
|
|
69
61
|
const s = flags.length > 1 ? "s" : "";
|
|
@@ -104,7 +96,18 @@ function compose(inspectors) {
|
|
|
104
96
|
}
|
|
105
97
|
|
|
106
98
|
//#endregion
|
|
107
|
-
//#region
|
|
99
|
+
//#region ../../node_modules/.pnpm/is-platform@1.0.0/node_modules/is-platform/dist/index.mjs
|
|
100
|
+
const IS_DENO = typeof Deno !== "undefined";
|
|
101
|
+
const IS_NODE = typeof process !== "undefined" && !IS_DENO;
|
|
102
|
+
const IS_ELECTRON = process.versions.electron && !process.defaultApp;
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/utils.ts
|
|
106
|
+
const normalizeFlagValue = (flag) => typeof flag === "function" || looseIsArray(flag) ? { type: flag } : flag;
|
|
107
|
+
const normalizeParameterValue = (parameter) => typeof parameter === "string" ? { key: parameter } : parameter;
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/parameter.ts
|
|
108
111
|
function getParametersToResolve(argv) {
|
|
109
112
|
const parameters = [];
|
|
110
113
|
for (const arg of argv) {
|
|
@@ -115,16 +118,21 @@ function getParametersToResolve(argv) {
|
|
|
115
118
|
}
|
|
116
119
|
const PARAMETER_REGEX = /^(<|\[)([\w ]+)(\.\.\.)?(\]|>)$/;
|
|
117
120
|
const isParameterDefinitionBracketsValid = (definition) => definition.startsWith("<") && definition.endsWith(">") || definition.startsWith("[") && definition.endsWith("]");
|
|
121
|
+
function extractParameterInfo(key) {
|
|
122
|
+
const match = key.match(PARAMETER_REGEX);
|
|
123
|
+
if (!match || !isParameterDefinitionBracketsValid(key)) throw new InvalidParametersError(`Invalid parameter definition: ${key}`);
|
|
124
|
+
return {
|
|
125
|
+
name: camelCase(match[2]),
|
|
126
|
+
isRequired: key.startsWith("<"),
|
|
127
|
+
isVariadic: !!match[3]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
118
130
|
function _parseParameters(definitions, parameters) {
|
|
119
131
|
const result = {};
|
|
120
132
|
let hasOptional = false;
|
|
121
|
-
for (const [i,
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
if (!match || !isParameterDefinitionBracketsValid(definitionKey)) throw new InvalidParametersError(`Invalid parameter definition: ${definitionKey}`);
|
|
125
|
-
const name = camelCase(match[2]);
|
|
126
|
-
const isVariadic = !!match[3];
|
|
127
|
-
const isRequired = definitionKey.startsWith("<");
|
|
133
|
+
for (const [i, def] of definitions.entries()) {
|
|
134
|
+
const normalized = normalizeParameterValue(def);
|
|
135
|
+
const { name, isRequired, isVariadic } = extractParameterInfo(normalized.key);
|
|
128
136
|
if (name in result) throw new InvalidParametersError(`Duplicate parameter name: ${name}`);
|
|
129
137
|
if (isVariadic && i !== definitions.length - 1) throw new InvalidParametersError("Variadic parameter must be the last parameter in the definition.");
|
|
130
138
|
if (isRequired) {
|
|
@@ -132,9 +140,9 @@ function _parseParameters(definitions, parameters) {
|
|
|
132
140
|
} else hasOptional = true;
|
|
133
141
|
const value = isVariadic ? parameters.slice(i) : parameters[i];
|
|
134
142
|
if (isRequired && (isVariadic ? value.length === 0 : value === void 0)) throw new InvalidParametersError(`Missing required ${isVariadic ? "variadic " : ""}parameter: ${name}`);
|
|
135
|
-
if (
|
|
143
|
+
if (normalized.type) if (isVariadic) result[name] = value.map((v) => normalized.type(v));
|
|
136
144
|
else if (value === void 0) result[name] = value;
|
|
137
|
-
else result[name] =
|
|
145
|
+
else result[name] = normalized.type(value);
|
|
138
146
|
else result[name] = value;
|
|
139
147
|
}
|
|
140
148
|
return result;
|
|
@@ -152,12 +160,6 @@ function parseParameters(definitions, parameters, doubleDashParameters) {
|
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region ../../node_modules/.pnpm/is-platform@1.0.0/node_modules/is-platform/dist/index.mjs
|
|
157
|
-
const IS_DENO = typeof Deno !== "undefined";
|
|
158
|
-
const IS_NODE = typeof process !== "undefined" && !IS_DENO;
|
|
159
|
-
const IS_ELECTRON = process.versions.electron && !process.defaultApp;
|
|
160
|
-
|
|
161
163
|
//#endregion
|
|
162
164
|
//#region src/platform.ts
|
|
163
165
|
const platformArgv = IS_NODE ? process.argv.slice(IS_ELECTRON ? 1 : 2) : IS_DENO ? Deno.args : [];
|
|
@@ -340,14 +342,6 @@ var Clerc = class Clerc {
|
|
|
340
342
|
}
|
|
341
343
|
};
|
|
342
344
|
|
|
343
|
-
//#endregion
|
|
344
|
-
//#region src/flag-types.ts
|
|
345
|
-
var flag_types_exports = /* @__PURE__ */ __export({
|
|
346
|
-
Enum: () => Enum,
|
|
347
|
-
Range: () => Range,
|
|
348
|
-
Regex: () => Regex
|
|
349
|
-
});
|
|
350
|
-
|
|
351
345
|
//#endregion
|
|
352
346
|
//#region src/helpers.ts
|
|
353
347
|
const defineCommand = (command, handler) => ({
|
|
@@ -373,8 +367,4 @@ function createStopAtFirstParameter() {
|
|
|
373
367
|
const definePlugin = (plugin) => plugin;
|
|
374
368
|
|
|
375
369
|
//#endregion
|
|
376
|
-
|
|
377
|
-
const normalizeFlagValue = (flag) => typeof flag === "function" || looseIsArray(flag) ? { type: flag } : flag;
|
|
378
|
-
|
|
379
|
-
//#endregion
|
|
380
|
-
export { Clerc, DOUBLE_DASH, InvalidCommandError, InvalidParametersError, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, flag_types_exports as Types, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, normalizeFlagValue, resolveCommand };
|
|
370
|
+
export { Clerc, DOUBLE_DASH, InvalidCommandError, InvalidParametersError, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, MissingRequiredMetadataError, NoCommandSpecifiedError, NoSuchCommandError, PARAMETER, Types, UNKNOWN_FLAG, createStopAtFirstParameter, defineCommand, definePlugin, extractParameterInfo, normalizeFlagValue, normalizeParameterValue, 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.29",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc core",
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"lite-emit": "^4.0.0",
|
|
48
|
-
"@clerc/
|
|
48
|
+
"@clerc/advanced-types": "1.0.0-beta.29",
|
|
49
|
+
"@clerc/parser": "1.0.0-beta.29"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"is-platform": "^1.0.0",
|
|
52
|
-
"@clerc/utils": "1.0.0-beta.
|
|
53
|
+
"@clerc/utils": "1.0.0-beta.29"
|
|
53
54
|
}
|
|
54
55
|
}
|
package/dist/chunk-CYeTv9WL.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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 };
|