clerc 0.34.1 → 0.35.0
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 +472 -473
- package/dist/index.js +23 -23
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -220,512 +220,511 @@ type LiteralUnion<
|
|
|
220
220
|
BaseType extends Primitive,
|
|
221
221
|
> = LiteralType | (BaseType & Record<never, never>);
|
|
222
222
|
|
|
223
|
-
type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
224
|
-
type Dict<T> = Record<string, T>;
|
|
225
|
-
type MaybeArray$1<T> = T | T[];
|
|
226
|
-
type AlphabetLowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
227
|
-
type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
228
|
-
type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
|
|
223
|
+
type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
224
|
+
type Dict<T> = Record<string, T>;
|
|
225
|
+
type MaybeArray$1<T> = T | T[];
|
|
226
|
+
type AlphabetLowercase = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
227
|
+
type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
228
|
+
type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
|
|
229
229
|
type CamelCase<Word extends string> = (Word extends `${infer FirstCharacter}${infer Rest}` ? (FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase<Rest>}` : Capitalize<CamelCase<Rest>>) : Word);
|
|
230
230
|
|
|
231
|
-
declare const DOUBLE_DASH = "--";
|
|
232
|
-
type TypeFunction<ReturnType = any> = (value: any) => ReturnType;
|
|
233
|
-
type TypeFunctionArray<ReturnType> = readonly [TypeFunction<ReturnType>];
|
|
234
|
-
type FlagType<ReturnType = any> = TypeFunction<ReturnType> | TypeFunctionArray<ReturnType>;
|
|
235
|
-
type FlagSchemaBase<TF> = {
|
|
236
|
-
/**
|
|
237
|
-
Type of the flag as a function that parses the argv string and returns the parsed value.
|
|
238
|
-
|
|
239
|
-
@example
|
|
240
|
-
```
|
|
241
|
-
type: String
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
@example Wrap in an array to accept multiple values.
|
|
245
|
-
```
|
|
246
|
-
type: [Boolean]
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
@example Custom function type that uses moment.js to parse string as date.
|
|
250
|
-
```
|
|
251
|
-
type: function CustomDate(value: string) {
|
|
252
|
-
return moment(value).toDate();
|
|
253
|
-
}
|
|
254
|
-
```
|
|
255
|
-
*/
|
|
256
|
-
type: TF;
|
|
257
|
-
/**
|
|
258
|
-
A single-character alias for the flag.
|
|
259
|
-
|
|
260
|
-
@example
|
|
261
|
-
```
|
|
262
|
-
alias: 's'
|
|
263
|
-
```
|
|
264
|
-
*/
|
|
265
|
-
alias?: string;
|
|
266
|
-
} & Record<PropertyKey, unknown>;
|
|
267
|
-
type FlagSchemaDefault<TF, DefaultType = any> = FlagSchemaBase<TF> & {
|
|
268
|
-
/**
|
|
269
|
-
Default value of the flag. Also accepts a function that returns the default value.
|
|
270
|
-
[Default: undefined]
|
|
271
|
-
|
|
272
|
-
@example
|
|
273
|
-
```
|
|
274
|
-
default: 'hello'
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
@example
|
|
278
|
-
```
|
|
279
|
-
default: () => [1, 2, 3]
|
|
280
|
-
```
|
|
281
|
-
*/
|
|
282
|
-
default: DefaultType | (() => DefaultType);
|
|
283
|
-
};
|
|
284
|
-
type FlagSchema<TF = FlagType> = (FlagSchemaBase<TF> | FlagSchemaDefault<TF>);
|
|
285
|
-
type FlagTypeOrSchema<ExtraOptions = Record<string, unknown>> = FlagType | (FlagSchema & ExtraOptions);
|
|
286
|
-
type Flags$1<ExtraOptions = Record<string, unknown>> = Record<string, FlagTypeOrSchema<ExtraOptions>>;
|
|
287
|
-
type InferFlagType<Flag extends FlagTypeOrSchema> = (Flag extends (TypeFunctionArray<infer T> | FlagSchema<TypeFunctionArray<infer T>>) ? (Flag extends FlagSchemaDefault<TypeFunctionArray<T>, infer D> ? T[] | D : T[]) : (Flag extends TypeFunction<infer T> | FlagSchema<TypeFunction<infer T>> ? (Flag extends FlagSchemaDefault<TypeFunction<T>, infer D> ? T | D : T | undefined) : never));
|
|
288
|
-
interface ParsedFlags<Schemas = Record<string, unknown>> {
|
|
289
|
-
flags: Schemas;
|
|
290
|
-
unknownFlags: Record<string, (string | boolean)[]>;
|
|
291
|
-
_: string[] & {
|
|
292
|
-
[DOUBLE_DASH]: string[];
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
type TypeFlag<Schemas extends Flags$1> = ParsedFlags<{
|
|
296
|
-
[flag in keyof Schemas]: InferFlagType<Schemas[flag]>;
|
|
231
|
+
declare const DOUBLE_DASH = "--";
|
|
232
|
+
type TypeFunction<ReturnType = any> = (value: any) => ReturnType;
|
|
233
|
+
type TypeFunctionArray<ReturnType> = readonly [TypeFunction<ReturnType>];
|
|
234
|
+
type FlagType<ReturnType = any> = TypeFunction<ReturnType> | TypeFunctionArray<ReturnType>;
|
|
235
|
+
type FlagSchemaBase<TF> = {
|
|
236
|
+
/**
|
|
237
|
+
Type of the flag as a function that parses the argv string and returns the parsed value.
|
|
238
|
+
|
|
239
|
+
@example
|
|
240
|
+
```
|
|
241
|
+
type: String
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
@example Wrap in an array to accept multiple values.
|
|
245
|
+
```
|
|
246
|
+
type: [Boolean]
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
@example Custom function type that uses moment.js to parse string as date.
|
|
250
|
+
```
|
|
251
|
+
type: function CustomDate(value: string) {
|
|
252
|
+
return moment(value).toDate();
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
*/
|
|
256
|
+
type: TF;
|
|
257
|
+
/**
|
|
258
|
+
A single-character alias for the flag.
|
|
259
|
+
|
|
260
|
+
@example
|
|
261
|
+
```
|
|
262
|
+
alias: 's'
|
|
263
|
+
```
|
|
264
|
+
*/
|
|
265
|
+
alias?: string;
|
|
266
|
+
} & Record<PropertyKey, unknown>;
|
|
267
|
+
type FlagSchemaDefault<TF, DefaultType = any> = FlagSchemaBase<TF> & {
|
|
268
|
+
/**
|
|
269
|
+
Default value of the flag. Also accepts a function that returns the default value.
|
|
270
|
+
[Default: undefined]
|
|
271
|
+
|
|
272
|
+
@example
|
|
273
|
+
```
|
|
274
|
+
default: 'hello'
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
@example
|
|
278
|
+
```
|
|
279
|
+
default: () => [1, 2, 3]
|
|
280
|
+
```
|
|
281
|
+
*/
|
|
282
|
+
default: DefaultType | (() => DefaultType);
|
|
283
|
+
};
|
|
284
|
+
type FlagSchema<TF = FlagType> = (FlagSchemaBase<TF> | FlagSchemaDefault<TF>);
|
|
285
|
+
type FlagTypeOrSchema<ExtraOptions = Record<string, unknown>> = FlagType | (FlagSchema & ExtraOptions);
|
|
286
|
+
type Flags$1<ExtraOptions = Record<string, unknown>> = Record<string, FlagTypeOrSchema<ExtraOptions>>;
|
|
287
|
+
type InferFlagType<Flag extends FlagTypeOrSchema> = (Flag extends (TypeFunctionArray<infer T> | FlagSchema<TypeFunctionArray<infer T>>) ? (Flag extends FlagSchemaDefault<TypeFunctionArray<T>, infer D> ? T[] | D : T[]) : (Flag extends TypeFunction<infer T> | FlagSchema<TypeFunction<infer T>> ? (Flag extends FlagSchemaDefault<TypeFunction<T>, infer D> ? T | D : T | undefined) : never));
|
|
288
|
+
interface ParsedFlags<Schemas = Record<string, unknown>> {
|
|
289
|
+
flags: Schemas;
|
|
290
|
+
unknownFlags: Record<string, (string | boolean)[]>;
|
|
291
|
+
_: string[] & {
|
|
292
|
+
[DOUBLE_DASH]: string[];
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
type TypeFlag<Schemas extends Flags$1> = ParsedFlags<{
|
|
296
|
+
[flag in keyof Schemas]: InferFlagType<Schemas[flag]>;
|
|
297
297
|
}>;
|
|
298
298
|
|
|
299
|
-
type StripBrackets<Parameter extends string> = (Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never);
|
|
300
|
-
type ParameterType<Parameter extends string> = (Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never);
|
|
301
|
-
type NonNullableParameters<T extends string[] | undefined> = T extends undefined ? [] : NonNullable<T>;
|
|
302
|
-
type TransformParameters<C extends Command> = {
|
|
303
|
-
[Parameter in NonNullableParameters<C["parameters"]>[number] as CamelCase<StripBrackets<Parameter>>]: ParameterType<Parameter>;
|
|
304
|
-
};
|
|
305
|
-
type MakeEventMap<T extends Commands> = {
|
|
306
|
-
[K in keyof T]: [InspectorContext];
|
|
307
|
-
};
|
|
308
|
-
type FallbackFlags<F extends Flags | undefined> = Equals<NonNullableFlag<F>["flags"], {}> extends true ? Dict<any> : NonNullableFlag<F>["flags"];
|
|
309
|
-
type NonNullableFlag<F extends Flags | undefined> = TypeFlag<NonNullable<F>>;
|
|
310
|
-
type ParseFlag<C extends Commands, N extends keyof C, GF extends GlobalFlagOptions = {}> = N extends keyof C ? OmitIndexSignature<NonNullableFlag<C[N]["flags"] & GF>["flags"]> : FallbackFlags<C[N]["flags"] & GF>["flags"];
|
|
311
|
-
type ParseRaw<C extends Command, GF extends GlobalFlagOptions = {}> = NonNullableFlag<C["flags"] & GF> & {
|
|
312
|
-
flags: FallbackFlags<C["flags"] & GF>;
|
|
313
|
-
parameters: string[];
|
|
314
|
-
mergedFlags: FallbackFlags<C["flags"] & GF> & NonNullableFlag<C["flags"] & GF>["unknownFlags"];
|
|
315
|
-
};
|
|
299
|
+
type StripBrackets<Parameter extends string> = (Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never);
|
|
300
|
+
type ParameterType<Parameter extends string> = (Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never);
|
|
301
|
+
type NonNullableParameters<T extends string[] | undefined> = T extends undefined ? [] : NonNullable<T>;
|
|
302
|
+
type TransformParameters<C extends Command> = {
|
|
303
|
+
[Parameter in NonNullableParameters<C["parameters"]>[number] as CamelCase<StripBrackets<Parameter>>]: ParameterType<Parameter>;
|
|
304
|
+
};
|
|
305
|
+
type MakeEventMap<T extends Commands> = {
|
|
306
|
+
[K in keyof T]: [InspectorContext];
|
|
307
|
+
};
|
|
308
|
+
type FallbackFlags<F extends Flags | undefined> = Equals<NonNullableFlag<F>["flags"], {}> extends true ? Dict<any> : NonNullableFlag<F>["flags"];
|
|
309
|
+
type NonNullableFlag<F extends Flags | undefined> = TypeFlag<NonNullable<F>>;
|
|
310
|
+
type ParseFlag<C extends Commands, N extends keyof C, GF extends GlobalFlagOptions = {}> = N extends keyof C ? OmitIndexSignature<NonNullableFlag<C[N]["flags"] & GF>["flags"]> : FallbackFlags<C[N]["flags"] & GF>["flags"];
|
|
311
|
+
type ParseRaw<C extends Command, GF extends GlobalFlagOptions = {}> = NonNullableFlag<C["flags"] & GF> & {
|
|
312
|
+
flags: FallbackFlags<C["flags"] & GF>;
|
|
313
|
+
parameters: string[];
|
|
314
|
+
mergedFlags: FallbackFlags<C["flags"] & GF> & NonNullableFlag<C["flags"] & GF>["unknownFlags"];
|
|
315
|
+
};
|
|
316
316
|
type ParseParameters<C extends Commands = Commands, N extends keyof C = keyof C> = Equals<TransformParameters<C[N]>, {}> extends true ? N extends keyof C ? TransformParameters<C[N]> : Dict<string | string[] | undefined> : TransformParameters<C[N]>;
|
|
317
317
|
|
|
318
|
-
interface Plugin<T extends Clerc = Clerc, U extends Clerc = Clerc> {
|
|
319
|
-
setup: (cli: T) => U;
|
|
318
|
+
interface Plugin<T extends Clerc = Clerc, U extends Clerc = Clerc> {
|
|
319
|
+
setup: (cli: T) => U;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
-
type Locales = Dict<Dict<string>>;
|
|
323
|
-
type TranslateFn = (name: string, ...args: string[]) => string | undefined;
|
|
324
|
-
interface I18N {
|
|
325
|
-
add: (locales: Locales) => void;
|
|
326
|
-
t: TranslateFn;
|
|
322
|
+
type Locales = Dict<Dict<string>>;
|
|
323
|
+
type TranslateFn = (name: string, ...args: string[]) => string | undefined;
|
|
324
|
+
interface I18N {
|
|
325
|
+
add: (locales: Locales) => void;
|
|
326
|
+
t: TranslateFn;
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
type CommandType = RootType | string;
|
|
330
|
-
type FlagOptions = FlagSchema & {
|
|
331
|
-
description: string;
|
|
332
|
-
};
|
|
333
|
-
type Flag = FlagOptions & {
|
|
334
|
-
name: string;
|
|
335
|
-
};
|
|
336
|
-
type GlobalFlagOption = FlagSchema;
|
|
337
|
-
type Flags = Dict<FlagOptions>;
|
|
338
|
-
type GlobalFlagOptions = Dict<GlobalFlagOption>;
|
|
339
|
-
declare interface CommandCustomProperties {
|
|
340
|
-
}
|
|
341
|
-
interface CommandOptions<P extends string[] = string[], A extends MaybeArray$1<string | RootType> = MaybeArray$1<string | RootType>, F extends Flags = Flags> extends CommandCustomProperties {
|
|
342
|
-
alias?: A;
|
|
343
|
-
parameters?: P;
|
|
344
|
-
flags?: F;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
enforce?: "pre" | "post";
|
|
389
|
-
fn: InspectorFn<C>;
|
|
329
|
+
type CommandType = RootType | string;
|
|
330
|
+
type FlagOptions = FlagSchema & {
|
|
331
|
+
description: string;
|
|
332
|
+
};
|
|
333
|
+
type Flag = FlagOptions & {
|
|
334
|
+
name: string;
|
|
335
|
+
};
|
|
336
|
+
type GlobalFlagOption = FlagSchema;
|
|
337
|
+
type Flags = Dict<FlagOptions>;
|
|
338
|
+
type GlobalFlagOptions = Dict<GlobalFlagOption>;
|
|
339
|
+
declare interface CommandCustomProperties {
|
|
340
|
+
}
|
|
341
|
+
interface CommandOptions<P extends string[] = string[], A extends MaybeArray$1<string | RootType> = MaybeArray$1<string | RootType>, F extends Flags = Flags> extends CommandCustomProperties {
|
|
342
|
+
alias?: A;
|
|
343
|
+
parameters?: P;
|
|
344
|
+
flags?: F;
|
|
345
|
+
}
|
|
346
|
+
type Command<N extends string | RootType = string, O extends CommandOptions = CommandOptions> = O & {
|
|
347
|
+
name: N;
|
|
348
|
+
description: string;
|
|
349
|
+
};
|
|
350
|
+
type CommandAlias<N extends string | RootType = string, O extends CommandOptions = CommandOptions> = Command<N, O> & {
|
|
351
|
+
__isAlias?: true;
|
|
352
|
+
};
|
|
353
|
+
type CommandWithHandler<N extends string | RootType = string, O extends CommandOptions = CommandOptions> = Command<N, O> & {
|
|
354
|
+
handler?: HandlerInCommand<HandlerContext<Record<N, Command<N, O>> & Record<never, never>, N>>;
|
|
355
|
+
};
|
|
356
|
+
type Commands = Dict<Command> & {
|
|
357
|
+
[Root]?: Command;
|
|
358
|
+
};
|
|
359
|
+
interface ParseOptions {
|
|
360
|
+
argv?: string[];
|
|
361
|
+
run?: boolean;
|
|
362
|
+
}
|
|
363
|
+
interface HandlerContext<C extends Commands = Commands, N extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> {
|
|
364
|
+
name?: LiteralUnion<N, string>;
|
|
365
|
+
called?: string | RootType;
|
|
366
|
+
resolved: boolean;
|
|
367
|
+
hasRootOrAlias: boolean;
|
|
368
|
+
hasRoot: boolean;
|
|
369
|
+
raw: Simplify<ParseRaw<C[N], GF>>;
|
|
370
|
+
parameters: Simplify<ParseParameters<C, N>>;
|
|
371
|
+
unknownFlags: ParsedFlags["unknownFlags"];
|
|
372
|
+
flags: Simplify<ParseFlag<C, N, GF> & Record<string, any>>;
|
|
373
|
+
cli: Clerc<C, GF>;
|
|
374
|
+
}
|
|
375
|
+
type Handler<C extends Commands = Commands, K extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> = (ctx: HandlerContext<C, K, GF>) => void;
|
|
376
|
+
type HandlerInCommand<C extends HandlerContext> = (ctx: {
|
|
377
|
+
[K in keyof C]: C[K];
|
|
378
|
+
}) => void;
|
|
379
|
+
type FallbackType<T, U> = {} extends T ? U : T;
|
|
380
|
+
type InspectorContext<C extends Commands = Commands> = HandlerContext<C> & {
|
|
381
|
+
flags: FallbackType<TypeFlag<NonNullable<C[keyof C]["flags"]>>["flags"], Dict<any>>;
|
|
382
|
+
};
|
|
383
|
+
type Inspector<C extends Commands = Commands> = InspectorFn<C> | InspectorObject<C>;
|
|
384
|
+
type InspectorFn<C extends Commands = Commands> = (ctx: InspectorContext<C>, next: () => void) => (() => void) | void;
|
|
385
|
+
interface InspectorObject<C extends Commands = Commands> {
|
|
386
|
+
enforce?: "pre" | "post";
|
|
387
|
+
fn: InspectorFn<C>;
|
|
390
388
|
}
|
|
391
389
|
|
|
392
|
-
declare const Root: unique symbol;
|
|
393
|
-
type RootType = typeof Root;
|
|
394
|
-
declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}> {
|
|
395
|
-
#private;
|
|
396
|
-
i18n: I18N;
|
|
397
|
-
private constructor();
|
|
398
|
-
get _name(): string;
|
|
399
|
-
get _description(): string;
|
|
400
|
-
get _version(): string;
|
|
401
|
-
get _inspectors(): Inspector
|
|
402
|
-
get _commands(): C;
|
|
403
|
-
get _flags(): GF;
|
|
404
|
-
/**
|
|
405
|
-
* Create a new cli
|
|
406
|
-
* @returns
|
|
407
|
-
* @example
|
|
408
|
-
* ```ts
|
|
409
|
-
* const cli = Clerc.create()
|
|
410
|
-
* ```
|
|
411
|
-
*/
|
|
412
|
-
static create(name?: string, description?: string, version?: string): Clerc<{}, {}>;
|
|
413
|
-
/**
|
|
414
|
-
* Set the name of the cli
|
|
415
|
-
* @param name
|
|
416
|
-
* @returns
|
|
417
|
-
* @example
|
|
418
|
-
* ```ts
|
|
419
|
-
* Clerc.create()
|
|
420
|
-
* .name("test")
|
|
421
|
-
* ```
|
|
422
|
-
*/
|
|
423
|
-
name(name: string): this;
|
|
424
|
-
/**
|
|
425
|
-
* Set the description of the cli
|
|
426
|
-
* @param description
|
|
427
|
-
* @returns
|
|
428
|
-
* @example
|
|
429
|
-
* ```ts
|
|
430
|
-
* Clerc.create()
|
|
431
|
-
* .description("test cli")
|
|
432
|
-
* ```
|
|
433
|
-
*/
|
|
434
|
-
description(description: string): this;
|
|
435
|
-
/**
|
|
436
|
-
* Set the version of the cli
|
|
437
|
-
* @param version
|
|
438
|
-
* @returns
|
|
439
|
-
* @example
|
|
440
|
-
* ```ts
|
|
441
|
-
* Clerc.create()
|
|
442
|
-
* .version("1.0.0")
|
|
443
|
-
* ```
|
|
444
|
-
*/
|
|
445
|
-
version(version: string): this;
|
|
446
|
-
/**
|
|
447
|
-
* Set the Locale
|
|
448
|
-
* You must call this method once after you created the Clerc instance.
|
|
449
|
-
* @param locale
|
|
450
|
-
* @returns
|
|
451
|
-
* @example
|
|
452
|
-
* ```ts
|
|
453
|
-
* Clerc.create()
|
|
454
|
-
* .locale("en")
|
|
455
|
-
* .command(...)
|
|
456
|
-
* ```
|
|
457
|
-
*/
|
|
458
|
-
locale(locale: string): this;
|
|
459
|
-
/**
|
|
460
|
-
* Set the fallback Locale
|
|
461
|
-
* You must call this method once after you created the Clerc instance.
|
|
462
|
-
* @param fallbackLocale
|
|
463
|
-
* @returns
|
|
464
|
-
* @example
|
|
465
|
-
* ```ts
|
|
466
|
-
* Clerc.create()
|
|
467
|
-
* .fallbackLocale("en")
|
|
468
|
-
* .command(...)
|
|
469
|
-
* ```
|
|
470
|
-
*/
|
|
471
|
-
fallbackLocale(fallbackLocale: string): this;
|
|
472
|
-
/**
|
|
473
|
-
* Register a error handler
|
|
474
|
-
* @param handler
|
|
475
|
-
* @returns
|
|
476
|
-
* @example
|
|
477
|
-
* ```ts
|
|
478
|
-
* Clerc.create()
|
|
479
|
-
* .errorHandler((err) => { console.log(err); })
|
|
480
|
-
* ```
|
|
481
|
-
*/
|
|
482
|
-
errorHandler(handler: (err: any) => void): this;
|
|
483
|
-
/**
|
|
484
|
-
* Register a command
|
|
485
|
-
* @param name
|
|
486
|
-
* @param description
|
|
487
|
-
* @param options
|
|
488
|
-
* @returns
|
|
489
|
-
* @example
|
|
490
|
-
* ```ts
|
|
491
|
-
* Clerc.create()
|
|
492
|
-
* .command("test", "test command", {
|
|
493
|
-
* alias: "t",
|
|
494
|
-
* flags: {
|
|
495
|
-
* foo: {
|
|
496
|
-
* alias: "f",
|
|
497
|
-
* description: "foo flag",
|
|
498
|
-
* }
|
|
499
|
-
* }
|
|
500
|
-
* })
|
|
501
|
-
* ```
|
|
502
|
-
* @example
|
|
503
|
-
* ```ts
|
|
504
|
-
* Clerc.create()
|
|
505
|
-
* .command("", "root", {
|
|
506
|
-
* flags: {
|
|
507
|
-
* foo: {
|
|
508
|
-
* alias: "f",
|
|
509
|
-
* description: "foo flag",
|
|
510
|
-
* }
|
|
511
|
-
* }
|
|
512
|
-
* })
|
|
513
|
-
* ```
|
|
514
|
-
*/
|
|
515
|
-
command<N extends string | RootType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray$1<string | RootType> = MaybeArray$1<string | RootType>, F extends Flags = Flags>(c: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>): this & Clerc<C & Record<N, Command<N, O>>, GF>;
|
|
516
|
-
command<N extends string | RootType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray$1<string | RootType> = MaybeArray$1<string | RootType>, F extends Flags = Flags>(name: N, description: string, options?: O & CommandOptions<[...P], A, F>): this & Clerc<C & Record<N, Command<N, O>>, GF>;
|
|
517
|
-
/**
|
|
518
|
-
* Register a global flag
|
|
519
|
-
* @param name
|
|
520
|
-
* @param description
|
|
521
|
-
* @param options
|
|
522
|
-
* @returns
|
|
523
|
-
* @example
|
|
524
|
-
* ```ts
|
|
525
|
-
* Clerc.create()
|
|
526
|
-
* .flag("help", "help", {
|
|
527
|
-
* alias: "h",
|
|
528
|
-
* type: Boolean,
|
|
529
|
-
* })
|
|
530
|
-
* ```
|
|
531
|
-
*/
|
|
532
|
-
flag<N extends string, O extends GlobalFlagOption>(name: N, description: string, options: O): this & Clerc<C, GF & Record<N, O>>;
|
|
533
|
-
/**
|
|
534
|
-
* Register a handler
|
|
535
|
-
* @param name
|
|
536
|
-
* @param handler
|
|
537
|
-
* @returns
|
|
538
|
-
* @example
|
|
539
|
-
* ```ts
|
|
540
|
-
* Clerc.create()
|
|
541
|
-
* .command("test", "test command")
|
|
542
|
-
* .on("test", (ctx) => {
|
|
543
|
-
* console.log(ctx);
|
|
544
|
-
* })
|
|
545
|
-
* ```
|
|
546
|
-
*/
|
|
547
|
-
on<K extends LiteralUnion<keyof CM, string | RootType>, CM extends this["_commands"] = this["_commands"]>(name: K, handler: Handler<CM, K, this["_flags"]>): this;
|
|
548
|
-
/**
|
|
549
|
-
* Use a plugin
|
|
550
|
-
* @param plugin
|
|
551
|
-
* @returns
|
|
552
|
-
* @example
|
|
553
|
-
* ```ts
|
|
554
|
-
* Clerc.create()
|
|
555
|
-
* .use(plugin)
|
|
556
|
-
* ```
|
|
557
|
-
*/
|
|
558
|
-
use<T extends Clerc, U extends Clerc>(plugin: Plugin<T, U>): this & Clerc<C & U["_commands"]> & U;
|
|
559
|
-
/**
|
|
560
|
-
* Register a inspector
|
|
561
|
-
* @param inspector
|
|
562
|
-
* @returns
|
|
563
|
-
* @example
|
|
564
|
-
* ```ts
|
|
565
|
-
* Clerc.create()
|
|
566
|
-
* .inspector((ctx, next) => {
|
|
567
|
-
* console.log(ctx);
|
|
568
|
-
* next();
|
|
569
|
-
* })
|
|
570
|
-
* ```
|
|
571
|
-
*/
|
|
572
|
-
inspector(inspector: Inspector): this;
|
|
573
|
-
/**
|
|
574
|
-
* Parse the command line arguments
|
|
575
|
-
* @param args
|
|
576
|
-
* @returns
|
|
577
|
-
* @example
|
|
578
|
-
* ```ts
|
|
579
|
-
* Clerc.create()
|
|
580
|
-
* .parse(process.argv.slice(2)) // Optional
|
|
581
|
-
* ```
|
|
582
|
-
*/
|
|
583
|
-
parse(optionsOrArgv?: string[] | ParseOptions): this;
|
|
584
|
-
/**
|
|
585
|
-
* Run matched command
|
|
586
|
-
* @returns
|
|
587
|
-
* @example
|
|
588
|
-
* ```ts
|
|
589
|
-
* Clerc.create()
|
|
590
|
-
* .parse({ run: false })
|
|
591
|
-
* .runMatchedCommand()
|
|
592
|
-
* ```
|
|
593
|
-
*/
|
|
594
|
-
runMatchedCommand(): this;
|
|
390
|
+
declare const Root: unique symbol;
|
|
391
|
+
type RootType = typeof Root;
|
|
392
|
+
declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}> {
|
|
393
|
+
#private;
|
|
394
|
+
i18n: I18N;
|
|
395
|
+
private constructor();
|
|
396
|
+
get _name(): string;
|
|
397
|
+
get _description(): string;
|
|
398
|
+
get _version(): string;
|
|
399
|
+
get _inspectors(): Inspector[];
|
|
400
|
+
get _commands(): C;
|
|
401
|
+
get _flags(): GF;
|
|
402
|
+
/**
|
|
403
|
+
* Create a new cli
|
|
404
|
+
* @returns
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* const cli = Clerc.create()
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
static create(name?: string, description?: string, version?: string): Clerc<{}, {}>;
|
|
411
|
+
/**
|
|
412
|
+
* Set the name of the cli
|
|
413
|
+
* @param name
|
|
414
|
+
* @returns
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* Clerc.create()
|
|
418
|
+
* .name("test")
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
name(name: string): this;
|
|
422
|
+
/**
|
|
423
|
+
* Set the description of the cli
|
|
424
|
+
* @param description
|
|
425
|
+
* @returns
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* Clerc.create()
|
|
429
|
+
* .description("test cli")
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
description(description: string): this;
|
|
433
|
+
/**
|
|
434
|
+
* Set the version of the cli
|
|
435
|
+
* @param version
|
|
436
|
+
* @returns
|
|
437
|
+
* @example
|
|
438
|
+
* ```ts
|
|
439
|
+
* Clerc.create()
|
|
440
|
+
* .version("1.0.0")
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
version(version: string): this;
|
|
444
|
+
/**
|
|
445
|
+
* Set the Locale
|
|
446
|
+
* You must call this method once after you created the Clerc instance.
|
|
447
|
+
* @param locale
|
|
448
|
+
* @returns
|
|
449
|
+
* @example
|
|
450
|
+
* ```ts
|
|
451
|
+
* Clerc.create()
|
|
452
|
+
* .locale("en")
|
|
453
|
+
* .command(...)
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
locale(locale: string): this;
|
|
457
|
+
/**
|
|
458
|
+
* Set the fallback Locale
|
|
459
|
+
* You must call this method once after you created the Clerc instance.
|
|
460
|
+
* @param fallbackLocale
|
|
461
|
+
* @returns
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* Clerc.create()
|
|
465
|
+
* .fallbackLocale("en")
|
|
466
|
+
* .command(...)
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
fallbackLocale(fallbackLocale: string): this;
|
|
470
|
+
/**
|
|
471
|
+
* Register a error handler
|
|
472
|
+
* @param handler
|
|
473
|
+
* @returns
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* Clerc.create()
|
|
477
|
+
* .errorHandler((err) => { console.log(err); })
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
errorHandler(handler: (err: any) => void): this;
|
|
481
|
+
/**
|
|
482
|
+
* Register a command
|
|
483
|
+
* @param name
|
|
484
|
+
* @param description
|
|
485
|
+
* @param options
|
|
486
|
+
* @returns
|
|
487
|
+
* @example
|
|
488
|
+
* ```ts
|
|
489
|
+
* Clerc.create()
|
|
490
|
+
* .command("test", "test command", {
|
|
491
|
+
* alias: "t",
|
|
492
|
+
* flags: {
|
|
493
|
+
* foo: {
|
|
494
|
+
* alias: "f",
|
|
495
|
+
* description: "foo flag",
|
|
496
|
+
* }
|
|
497
|
+
* }
|
|
498
|
+
* })
|
|
499
|
+
* ```
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* Clerc.create()
|
|
503
|
+
* .command("", "root", {
|
|
504
|
+
* flags: {
|
|
505
|
+
* foo: {
|
|
506
|
+
* alias: "f",
|
|
507
|
+
* description: "foo flag",
|
|
508
|
+
* }
|
|
509
|
+
* }
|
|
510
|
+
* })
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
command<N extends string | RootType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray$1<string | RootType> = MaybeArray$1<string | RootType>, F extends Flags = Flags>(c: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>): this & Clerc<C & Record<N, Command<N, O>>, GF>;
|
|
514
|
+
command<N extends string | RootType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray$1<string | RootType> = MaybeArray$1<string | RootType>, F extends Flags = Flags>(name: N, description: string, options?: O & CommandOptions<[...P], A, F>): this & Clerc<C & Record<N, Command<N, O>>, GF>;
|
|
515
|
+
/**
|
|
516
|
+
* Register a global flag
|
|
517
|
+
* @param name
|
|
518
|
+
* @param description
|
|
519
|
+
* @param options
|
|
520
|
+
* @returns
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* Clerc.create()
|
|
524
|
+
* .flag("help", "help", {
|
|
525
|
+
* alias: "h",
|
|
526
|
+
* type: Boolean,
|
|
527
|
+
* })
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
flag<N extends string, O extends GlobalFlagOption>(name: N, description: string, options: O): this & Clerc<C, GF & Record<N, O>>;
|
|
531
|
+
/**
|
|
532
|
+
* Register a handler
|
|
533
|
+
* @param name
|
|
534
|
+
* @param handler
|
|
535
|
+
* @returns
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* Clerc.create()
|
|
539
|
+
* .command("test", "test command")
|
|
540
|
+
* .on("test", (ctx) => {
|
|
541
|
+
* console.log(ctx);
|
|
542
|
+
* })
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
on<K extends LiteralUnion<keyof CM, string | RootType>, CM extends this["_commands"] = this["_commands"]>(name: K, handler: Handler<CM, K, this["_flags"]>): this;
|
|
546
|
+
/**
|
|
547
|
+
* Use a plugin
|
|
548
|
+
* @param plugin
|
|
549
|
+
* @returns
|
|
550
|
+
* @example
|
|
551
|
+
* ```ts
|
|
552
|
+
* Clerc.create()
|
|
553
|
+
* .use(plugin)
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
use<T extends Clerc, U extends Clerc>(plugin: Plugin<T, U>): this & Clerc<C & U["_commands"]> & U;
|
|
557
|
+
/**
|
|
558
|
+
* Register a inspector
|
|
559
|
+
* @param inspector
|
|
560
|
+
* @returns
|
|
561
|
+
* @example
|
|
562
|
+
* ```ts
|
|
563
|
+
* Clerc.create()
|
|
564
|
+
* .inspector((ctx, next) => {
|
|
565
|
+
* console.log(ctx);
|
|
566
|
+
* next();
|
|
567
|
+
* })
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
inspector(inspector: Inspector): this;
|
|
571
|
+
/**
|
|
572
|
+
* Parse the command line arguments
|
|
573
|
+
* @param args
|
|
574
|
+
* @returns
|
|
575
|
+
* @example
|
|
576
|
+
* ```ts
|
|
577
|
+
* Clerc.create()
|
|
578
|
+
* .parse(process.argv.slice(2)) // Optional
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
parse(optionsOrArgv?: string[] | ParseOptions): this;
|
|
582
|
+
/**
|
|
583
|
+
* Run matched command
|
|
584
|
+
* @returns
|
|
585
|
+
* @example
|
|
586
|
+
* ```ts
|
|
587
|
+
* Clerc.create()
|
|
588
|
+
* .parse({ run: false })
|
|
589
|
+
* .runMatchedCommand()
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
runMatchedCommand(): this;
|
|
595
593
|
}
|
|
596
594
|
|
|
597
595
|
type MaybeArray<T> = T | T[];
|
|
598
596
|
|
|
599
|
-
declare const definePlugin: <T extends Clerc<{}, {}>, U extends Clerc<{}, {}>>(p: Plugin<T, U>) => Plugin<T, U>;
|
|
600
|
-
declare const defineHandler: <C extends Clerc<{}, {}>, K extends keyof C["_commands"]>(_cli: C, _key: K, handler: Handler<C["_commands"], K
|
|
601
|
-
declare const defineInspector: <C extends Clerc<{}, {}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
|
|
597
|
+
declare const definePlugin: <T extends Clerc<{}, {}>, U extends Clerc<{}, {}>>(p: Plugin<T, U>) => Plugin<T, U>;
|
|
598
|
+
declare const defineHandler: <C extends Clerc<{}, {}>, K extends keyof C["_commands"]>(_cli: C, _key: K, handler: Handler<C["_commands"], K>) => Handler<C["_commands"], K>;
|
|
599
|
+
declare const defineInspector: <C extends Clerc<{}, {}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
|
|
602
600
|
declare const defineCommand: <N extends string | typeof Root, O extends CommandOptions<[...P], MaybeArray<string | typeof Root>, Flags>, P extends string[]>(command: Command<N, O & CommandOptions<[...P], MaybeArray<string | typeof Root>, Flags>>, handler?: HandlerInCommand<HandlerContext<Record<N, Command<N, O>> & Record<never, never>, N, {}>> | undefined) => CommandWithHandler<N, O & CommandOptions<[...P], MaybeArray<string | typeof Root>, Flags>>;
|
|
603
601
|
|
|
604
|
-
declare class CommandExistsError extends Error {
|
|
605
|
-
commandName: string;
|
|
606
|
-
constructor(commandName: string, t: TranslateFn);
|
|
607
|
-
}
|
|
608
|
-
declare class NoSuchCommandError extends Error {
|
|
609
|
-
commandName: string;
|
|
610
|
-
constructor(commandName: string, t: TranslateFn);
|
|
611
|
-
}
|
|
612
|
-
declare class NoCommandGivenError extends Error {
|
|
613
|
-
constructor(t: TranslateFn);
|
|
614
|
-
}
|
|
615
|
-
declare class CommandNameConflictError extends Error {
|
|
616
|
-
n1: string;
|
|
617
|
-
n2: string;
|
|
618
|
-
constructor(n1: string, n2: string, t: TranslateFn);
|
|
619
|
-
}
|
|
620
|
-
declare class NameNotSetError extends Error {
|
|
621
|
-
constructor(t: TranslateFn);
|
|
622
|
-
}
|
|
623
|
-
declare class DescriptionNotSetError extends Error {
|
|
624
|
-
constructor(t: TranslateFn);
|
|
625
|
-
}
|
|
626
|
-
declare class VersionNotSetError extends Error {
|
|
627
|
-
constructor(t: TranslateFn);
|
|
628
|
-
}
|
|
629
|
-
declare class InvalidCommandNameError extends Error {
|
|
630
|
-
commandName: string;
|
|
631
|
-
constructor(commandName: string, t: TranslateFn);
|
|
632
|
-
}
|
|
633
|
-
declare class LocaleNotCalledFirstError extends Error {
|
|
634
|
-
constructor(t: TranslateFn);
|
|
602
|
+
declare class CommandExistsError extends Error {
|
|
603
|
+
commandName: string;
|
|
604
|
+
constructor(commandName: string, t: TranslateFn);
|
|
605
|
+
}
|
|
606
|
+
declare class NoSuchCommandError extends Error {
|
|
607
|
+
commandName: string;
|
|
608
|
+
constructor(commandName: string, t: TranslateFn);
|
|
609
|
+
}
|
|
610
|
+
declare class NoCommandGivenError extends Error {
|
|
611
|
+
constructor(t: TranslateFn);
|
|
612
|
+
}
|
|
613
|
+
declare class CommandNameConflictError extends Error {
|
|
614
|
+
n1: string;
|
|
615
|
+
n2: string;
|
|
616
|
+
constructor(n1: string, n2: string, t: TranslateFn);
|
|
617
|
+
}
|
|
618
|
+
declare class NameNotSetError extends Error {
|
|
619
|
+
constructor(t: TranslateFn);
|
|
620
|
+
}
|
|
621
|
+
declare class DescriptionNotSetError extends Error {
|
|
622
|
+
constructor(t: TranslateFn);
|
|
623
|
+
}
|
|
624
|
+
declare class VersionNotSetError extends Error {
|
|
625
|
+
constructor(t: TranslateFn);
|
|
626
|
+
}
|
|
627
|
+
declare class InvalidCommandNameError extends Error {
|
|
628
|
+
commandName: string;
|
|
629
|
+
constructor(commandName: string, t: TranslateFn);
|
|
630
|
+
}
|
|
631
|
+
declare class LocaleNotCalledFirstError extends Error {
|
|
632
|
+
constructor(t: TranslateFn);
|
|
635
633
|
}
|
|
636
634
|
|
|
637
|
-
declare function resolveFlattenCommands(commands: Commands, t: TranslateFn): Map<string[] | typeof Root, CommandAlias
|
|
638
|
-
declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined];
|
|
639
|
-
declare
|
|
640
|
-
declare function
|
|
641
|
-
declare const
|
|
642
|
-
declare const
|
|
643
|
-
declare
|
|
644
|
-
declare const
|
|
645
|
-
declare const withBrackets: (s: string, isOptional?: boolean) => string;
|
|
646
|
-
declare const formatCommandName: (name: string | string[] | RootType) => string;
|
|
647
|
-
declare const detectLocale: () => string;
|
|
635
|
+
declare function resolveFlattenCommands(commands: Commands, t: TranslateFn): Map<string[] | typeof Root, CommandAlias>;
|
|
636
|
+
declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined];
|
|
637
|
+
declare const resolveArgv: () => string[];
|
|
638
|
+
declare function compose(inspectors: Inspector[]): (ctx: InspectorContext) => void;
|
|
639
|
+
declare const isValidName: (name: CommandType) => boolean;
|
|
640
|
+
declare const withBrackets: (s: string, isOptional?: boolean) => string;
|
|
641
|
+
declare const formatCommandName: (name: string | string[] | RootType) => string;
|
|
642
|
+
declare const detectLocale: () => string;
|
|
648
643
|
declare const stripFlags: (argv: string[]) => string[];
|
|
649
644
|
|
|
650
|
-
interface CompletionsPluginOptions {
|
|
651
|
-
command?: boolean;
|
|
652
|
-
}
|
|
645
|
+
interface CompletionsPluginOptions {
|
|
646
|
+
command?: boolean;
|
|
647
|
+
}
|
|
653
648
|
declare const completionsPlugin: (options?: CompletionsPluginOptions) => Plugin<Clerc<{}, {}>, Clerc<{}, {}>>;
|
|
654
649
|
|
|
655
|
-
interface BlockSection {
|
|
656
|
-
type?: "block";
|
|
657
|
-
title: string;
|
|
658
|
-
body: string[];
|
|
659
|
-
}
|
|
660
|
-
interface InlineSection {
|
|
661
|
-
type: "inline";
|
|
662
|
-
items: {
|
|
663
|
-
title: string;
|
|
664
|
-
body: string;
|
|
665
|
-
}[];
|
|
666
|
-
}
|
|
667
|
-
type Section = BlockSection | InlineSection;
|
|
668
|
-
interface Renderers {
|
|
669
|
-
renderSections?: (sections: Section[]) => Section[];
|
|
670
|
-
renderFlagName?: (name: string) => string;
|
|
671
|
-
renderType?: (type: any, hasDefault: boolean) => string;
|
|
672
|
-
renderDefault?: (default_: any) => string;
|
|
650
|
+
interface BlockSection {
|
|
651
|
+
type?: "block";
|
|
652
|
+
title: string;
|
|
653
|
+
body: string[];
|
|
654
|
+
}
|
|
655
|
+
interface InlineSection {
|
|
656
|
+
type: "inline";
|
|
657
|
+
items: {
|
|
658
|
+
title: string;
|
|
659
|
+
body: string;
|
|
660
|
+
}[];
|
|
661
|
+
}
|
|
662
|
+
type Section = BlockSection | InlineSection;
|
|
663
|
+
interface Renderers {
|
|
664
|
+
renderSections?: (sections: Section[]) => Section[];
|
|
665
|
+
renderFlagName?: (name: string) => string;
|
|
666
|
+
renderType?: (type: any, hasDefault: boolean) => string;
|
|
667
|
+
renderDefault?: (default_: any) => string;
|
|
673
668
|
}
|
|
674
669
|
|
|
675
|
-
declare module "@clerc/core" {
|
|
676
|
-
interface CommandCustomProperties {
|
|
677
|
-
help?:
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
*
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
*
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
*
|
|
698
|
-
*/
|
|
699
|
-
|
|
700
|
-
/**
|
|
701
|
-
* Global
|
|
702
|
-
*/
|
|
703
|
-
|
|
704
|
-
/**
|
|
705
|
-
*
|
|
706
|
-
*/
|
|
707
|
-
|
|
708
|
-
|
|
670
|
+
declare module "@clerc/core" {
|
|
671
|
+
interface CommandCustomProperties {
|
|
672
|
+
help?: {
|
|
673
|
+
renderers?: Renderers;
|
|
674
|
+
examples?: [string, string][];
|
|
675
|
+
notes?: string[];
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
interface HelpPluginOptions {
|
|
680
|
+
/**
|
|
681
|
+
* Whether to register the help command.
|
|
682
|
+
* @default true
|
|
683
|
+
*/
|
|
684
|
+
command?: boolean;
|
|
685
|
+
/**
|
|
686
|
+
* Whether to register the global help flag.
|
|
687
|
+
* @default true
|
|
688
|
+
*/
|
|
689
|
+
flag?: boolean;
|
|
690
|
+
/**
|
|
691
|
+
* Whether to show help when no command is specified.
|
|
692
|
+
* @default true
|
|
693
|
+
*/
|
|
694
|
+
showHelpWhenNoCommand?: boolean;
|
|
695
|
+
/**
|
|
696
|
+
* Global notes.
|
|
697
|
+
*/
|
|
698
|
+
notes?: string[];
|
|
699
|
+
/**
|
|
700
|
+
* Global examples.
|
|
701
|
+
*/
|
|
702
|
+
examples?: [string, string][];
|
|
703
|
+
/**
|
|
704
|
+
* Banner.
|
|
705
|
+
*/
|
|
706
|
+
banner?: string;
|
|
707
|
+
}
|
|
709
708
|
declare const helpPlugin: ({ command, flag, showHelpWhenNoCommand, notes, examples, banner, }?: HelpPluginOptions) => Plugin<Clerc<{}, {}>, Clerc<{}, {}>>;
|
|
710
709
|
|
|
711
710
|
declare const notFoundPlugin: () => Plugin<Clerc<{}, {}>, Clerc<{}, {}>>;
|
|
712
711
|
|
|
713
712
|
declare const strictFlagsPlugin: () => Plugin<Clerc<{}, {}>, Clerc<{}, {}>>;
|
|
714
713
|
|
|
715
|
-
interface VersionPluginOptions {
|
|
716
|
-
/**
|
|
717
|
-
* Whether to register the help command.
|
|
718
|
-
* @default true
|
|
719
|
-
*/
|
|
720
|
-
command?: boolean;
|
|
721
|
-
/**
|
|
722
|
-
* Whether to register the global help flag.
|
|
723
|
-
* @default true
|
|
724
|
-
*/
|
|
725
|
-
flag?: boolean;
|
|
726
|
-
}
|
|
714
|
+
interface VersionPluginOptions {
|
|
715
|
+
/**
|
|
716
|
+
* Whether to register the help command.
|
|
717
|
+
* @default true
|
|
718
|
+
*/
|
|
719
|
+
command?: boolean;
|
|
720
|
+
/**
|
|
721
|
+
* Whether to register the global help flag.
|
|
722
|
+
* @default true
|
|
723
|
+
*/
|
|
724
|
+
flag?: boolean;
|
|
725
|
+
}
|
|
727
726
|
declare const versionPlugin: ({ command, flag, }?: VersionPluginOptions) => Plugin<Clerc<{}, {}>, Clerc<{}, {}>>;
|
|
728
727
|
|
|
729
728
|
declare const friendlyErrorPlugin: () => Plugin<Clerc<{}, {}>, Clerc<{}, {}>>;
|
|
730
729
|
|
|
731
|
-
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, CompletionsPluginOptions, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, HelpPluginOptions, I18N, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, TranslateFn, VersionNotSetError, completionsPlugin, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, friendlyErrorPlugin, helpPlugin, isValidName, notFoundPlugin, resolveArgv, resolveCommand,
|
|
730
|
+
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, CompletionsPluginOptions, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, HelpPluginOptions, I18N, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, TranslateFn, VersionNotSetError, completionsPlugin, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, friendlyErrorPlugin, helpPlugin, isValidName, notFoundPlugin, resolveArgv, resolveCommand, resolveFlattenCommands, strictFlagsPlugin, stripFlags, versionPlugin, withBrackets };
|