@clerc/core 0.39.0 → 0.41.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/LICENSE +21 -21
- package/README.md +9 -0
- package/dist/index.d.ts +161 -348
- package/dist/index.js +795 -1
- package/package.json +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,232 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type MaybeArray$1<T> = T | T[];
|
|
4
|
-
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";
|
|
5
|
-
type Numeric = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
6
|
-
type AlphaNumeric = AlphabetLowercase | Uppercase<AlphabetLowercase> | Numeric;
|
|
7
|
-
type CamelCase<Word extends string> = Word extends `${infer FirstCharacter}${infer Rest}` ? (FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase<Rest>}` : Capitalize<CamelCase<Rest>>) : Word;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
11
|
-
|
|
12
|
-
@category Type
|
|
13
|
-
*/
|
|
14
|
-
type Primitive =
|
|
15
|
-
| null
|
|
16
|
-
| undefined
|
|
17
|
-
| string
|
|
18
|
-
| number
|
|
19
|
-
| boolean
|
|
20
|
-
| symbol
|
|
21
|
-
| bigint;
|
|
22
|
-
|
|
23
|
-
declare global {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
25
|
-
interface SymbolConstructor {
|
|
26
|
-
readonly observable: symbol;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
32
|
-
|
|
33
|
-
@example
|
|
34
|
-
```
|
|
35
|
-
import type {Simplify} from 'type-fest';
|
|
36
|
-
|
|
37
|
-
type PositionProps = {
|
|
38
|
-
top: number;
|
|
39
|
-
left: number;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
type SizeProps = {
|
|
43
|
-
width: number;
|
|
44
|
-
height: number;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
48
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
52
|
-
|
|
53
|
-
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
54
|
-
|
|
55
|
-
@example
|
|
56
|
-
```
|
|
57
|
-
import type {Simplify} from 'type-fest';
|
|
58
|
-
|
|
59
|
-
interface SomeInterface {
|
|
60
|
-
foo: number;
|
|
61
|
-
bar?: string;
|
|
62
|
-
baz: number | undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
type SomeType = {
|
|
66
|
-
foo: number;
|
|
67
|
-
bar?: string;
|
|
68
|
-
baz: number | undefined;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
72
|
-
const someType: SomeType = literal;
|
|
73
|
-
const someInterface: SomeInterface = literal;
|
|
74
|
-
|
|
75
|
-
function fn(object: Record<string, unknown>): void {}
|
|
76
|
-
|
|
77
|
-
fn(literal); // Good: literal object type is sealed
|
|
78
|
-
fn(someType); // Good: type is sealed
|
|
79
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
80
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
84
|
-
|
|
85
|
-
@category Object
|
|
86
|
-
*/
|
|
87
|
-
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
91
|
-
|
|
92
|
-
This is the counterpart of `PickIndexSignature`.
|
|
93
|
-
|
|
94
|
-
Use-cases:
|
|
95
|
-
- Remove overly permissive signatures from third-party types.
|
|
96
|
-
|
|
97
|
-
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
98
|
-
|
|
99
|
-
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
100
|
-
|
|
101
|
-
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
const indexed: Record<string, unknown> = {}; // Allowed
|
|
105
|
-
|
|
106
|
-
const keyed: Record<'foo', unknown> = {}; // Error
|
|
107
|
-
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
111
|
-
|
|
112
|
-
```
|
|
113
|
-
type Indexed = {} extends Record<string, unknown>
|
|
114
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
115
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
116
|
-
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
117
|
-
|
|
118
|
-
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
119
|
-
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
120
|
-
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
121
|
-
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
128
|
-
|
|
129
|
-
type OmitIndexSignature<ObjectType> = {
|
|
130
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
131
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
132
|
-
};
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
136
|
-
|
|
137
|
-
```
|
|
138
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
139
|
-
|
|
140
|
-
type OmitIndexSignature<ObjectType> = {
|
|
141
|
-
[KeyType in keyof ObjectType
|
|
142
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
143
|
-
as {} extends Record<KeyType, unknown>
|
|
144
|
-
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
145
|
-
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
146
|
-
]: ObjectType[KeyType];
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
154
|
-
|
|
155
|
-
type OmitIndexSignature<ObjectType> = {
|
|
156
|
-
[KeyType in keyof ObjectType
|
|
157
|
-
as {} extends Record<KeyType, unknown>
|
|
158
|
-
? never // => Remove this `KeyType`.
|
|
159
|
-
: KeyType // => Keep this `KeyType` as it is.
|
|
160
|
-
]: ObjectType[KeyType];
|
|
161
|
-
};
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
@example
|
|
165
|
-
```
|
|
166
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
167
|
-
|
|
168
|
-
interface Example {
|
|
169
|
-
// These index signatures will be removed.
|
|
170
|
-
[x: string]: any
|
|
171
|
-
[x: number]: any
|
|
172
|
-
[x: symbol]: any
|
|
173
|
-
[x: `head-${string}`]: string
|
|
174
|
-
[x: `${string}-tail`]: string
|
|
175
|
-
[x: `head-${string}-tail`]: string
|
|
176
|
-
[x: `${bigint}`]: string
|
|
177
|
-
[x: `embedded-${number}`]: string
|
|
178
|
-
|
|
179
|
-
// These explicitly defined keys will remain.
|
|
180
|
-
foo: 'bar';
|
|
181
|
-
qux?: 'baz';
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
185
|
-
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
@see PickIndexSignature
|
|
189
|
-
@category Object
|
|
190
|
-
*/
|
|
191
|
-
type OmitIndexSignature<ObjectType> = {
|
|
192
|
-
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
193
|
-
? never
|
|
194
|
-
: KeyType]: ObjectType[KeyType];
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
199
|
-
|
|
200
|
-
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
|
201
|
-
|
|
202
|
-
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
|
203
|
-
|
|
204
|
-
@example
|
|
205
|
-
```
|
|
206
|
-
import type {LiteralUnion} from 'type-fest';
|
|
207
|
-
|
|
208
|
-
// Before
|
|
209
|
-
|
|
210
|
-
type Pet = 'dog' | 'cat' | string;
|
|
211
|
-
|
|
212
|
-
const pet: Pet = '';
|
|
213
|
-
// Start typing in your TypeScript-enabled IDE.
|
|
214
|
-
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
215
|
-
|
|
216
|
-
// After
|
|
217
|
-
|
|
218
|
-
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
219
|
-
|
|
220
|
-
const pet: Pet2 = '';
|
|
221
|
-
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
@category Type
|
|
225
|
-
*/
|
|
226
|
-
type LiteralUnion<
|
|
227
|
-
LiteralType,
|
|
228
|
-
BaseType extends Primitive,
|
|
229
|
-
> = LiteralType | (BaseType & Record<never, never>);
|
|
1
|
+
import { Equals, Dict, CamelCase, MaybeArray as MaybeArray$1 } from '@clerc/utils';
|
|
2
|
+
import { OmitIndexSignature, LiteralUnion, Simplify } from 'type-fest';
|
|
230
3
|
|
|
231
4
|
declare const DOUBLE_DASH = "--";
|
|
232
5
|
type TypeFunction<ReturnType = any> = (value: any) => ReturnType;
|
|
@@ -234,54 +7,60 @@ type TypeFunctionArray<ReturnType> = readonly [TypeFunction<ReturnType>];
|
|
|
234
7
|
type FlagType<ReturnType = any> = TypeFunction<ReturnType> | TypeFunctionArray<ReturnType>;
|
|
235
8
|
type FlagSchemaBase<TF> = {
|
|
236
9
|
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
```
|
|
10
|
+
* Type of the flag as a function that parses the argv string and returns the
|
|
11
|
+
* parsed value.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* type: String
|
|
17
|
+
* ```
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Wrap in an array to accept multiple values. `type: [Boolean]`
|
|
21
|
+
*
|
|
22
|
+
* @example Custom function type that uses moment.js to parse string as date.
|
|
23
|
+
* `type: function CustomDate(value: string) { return moment(value).toDate();
|
|
24
|
+
* }`
|
|
253
25
|
*/
|
|
254
26
|
type: TF;
|
|
255
27
|
/**
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
28
|
+
* A single-character alias for the flag.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
*
|
|
32
|
+
* ```
|
|
33
|
+
* alias: 's'
|
|
34
|
+
* ```
|
|
35
|
+
* ```
|
|
262
36
|
*/
|
|
263
37
|
alias?: string;
|
|
264
38
|
} & Record<PropertyKey, unknown>;
|
|
265
39
|
type FlagSchemaDefault<TF, DefaultType = any> = FlagSchemaBase<TF> & {
|
|
266
40
|
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
41
|
+
* Default value of the flag. Also accepts a function that returns the default
|
|
42
|
+
* value. [Default: undefined]
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* default: 'hello'
|
|
48
|
+
* ```
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
* default: () => [1, 2, 3]
|
|
55
|
+
* ```
|
|
56
|
+
* ```
|
|
278
57
|
*/
|
|
279
58
|
default: DefaultType | (() => DefaultType);
|
|
280
59
|
};
|
|
281
60
|
type FlagSchema<TF = FlagType> = FlagSchemaBase<TF> | FlagSchemaDefault<TF>;
|
|
282
61
|
type FlagTypeOrSchema<ExtraOptions = Record<string, unknown>> = FlagType | (FlagSchema & ExtraOptions);
|
|
283
62
|
type Flags$1<ExtraOptions = Record<string, unknown>> = Record<string, FlagTypeOrSchema<ExtraOptions>>;
|
|
284
|
-
type InferFlagType<Flag extends FlagTypeOrSchema> = Flag extends
|
|
63
|
+
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;
|
|
285
64
|
interface ParsedFlags<Schemas = Record<string, unknown>> {
|
|
286
65
|
flags: Schemas;
|
|
287
66
|
unknownFlags: Record<string, (string | boolean)[]>;
|
|
@@ -293,7 +72,7 @@ type TypeFlag<Schemas extends Flags$1> = ParsedFlags<{
|
|
|
293
72
|
[flag in keyof Schemas]: InferFlagType<Schemas[flag]>;
|
|
294
73
|
}>;
|
|
295
74
|
|
|
296
|
-
type StripBrackets<Parameter extends string> = Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ?
|
|
75
|
+
type StripBrackets<Parameter extends string> = Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName : never;
|
|
297
76
|
type ParameterType<Parameter extends string> = Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never;
|
|
298
77
|
type NonNullableParameters<T extends string[] | undefined> = T extends undefined ? [] : NonNullable<T>;
|
|
299
78
|
type TransformParameters<C extends Command> = {
|
|
@@ -391,6 +170,7 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
391
170
|
i18n: I18N;
|
|
392
171
|
private constructor();
|
|
393
172
|
get _name(): string;
|
|
173
|
+
get _scriptName(): string;
|
|
394
174
|
get _description(): string;
|
|
395
175
|
get _version(): string;
|
|
396
176
|
get _inspectors(): Inspector[];
|
|
@@ -399,210 +179,243 @@ declare class Clerc<C extends Commands = {}, GF extends GlobalFlagOptions = {}>
|
|
|
399
179
|
/**
|
|
400
180
|
* Create a new cli
|
|
401
181
|
*
|
|
182
|
+
* @example
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* const cli = Clerc.create();
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
402
188
|
* @param name
|
|
403
189
|
* @param description
|
|
404
190
|
* @param version
|
|
405
191
|
* @returns
|
|
406
|
-
* @example
|
|
407
|
-
* ```ts
|
|
408
|
-
* const cli = Clerc.create()
|
|
409
|
-
* ```
|
|
410
192
|
*/
|
|
411
193
|
static create(name?: string, description?: string, version?: string): Clerc<{}, {}>;
|
|
412
194
|
/**
|
|
413
195
|
* Set the name of the cli
|
|
414
196
|
*
|
|
197
|
+
* @example
|
|
198
|
+
*
|
|
199
|
+
* ```ts
|
|
200
|
+
* Clerc.create().name("test");
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
415
203
|
* @param name
|
|
416
204
|
* @returns
|
|
205
|
+
*/
|
|
206
|
+
name(name: string): this;
|
|
207
|
+
/**
|
|
208
|
+
* Set the script name of the cli
|
|
209
|
+
*
|
|
417
210
|
* @example
|
|
211
|
+
*
|
|
418
212
|
* ```ts
|
|
419
|
-
* Clerc.create()
|
|
420
|
-
* .name("test")
|
|
213
|
+
* Clerc.create().scriptName("test");
|
|
421
214
|
* ```
|
|
215
|
+
*
|
|
216
|
+
* @param scriptName
|
|
217
|
+
* @returns
|
|
422
218
|
*/
|
|
423
|
-
|
|
219
|
+
scriptName(scriptName: string): this;
|
|
424
220
|
/**
|
|
425
221
|
* Set the description of the cli
|
|
426
222
|
*
|
|
427
|
-
* @param description
|
|
428
|
-
* @returns
|
|
429
223
|
* @example
|
|
224
|
+
*
|
|
430
225
|
* ```ts
|
|
431
|
-
* Clerc.create()
|
|
432
|
-
* .description("test cli")
|
|
226
|
+
* Clerc.create().description("test cli");
|
|
433
227
|
* ```
|
|
228
|
+
*
|
|
229
|
+
* @param description
|
|
230
|
+
* @returns
|
|
434
231
|
*/
|
|
435
232
|
description(description: string): this;
|
|
436
233
|
/**
|
|
437
234
|
* Set the version of the cli
|
|
438
235
|
*
|
|
439
|
-
* @param version
|
|
440
|
-
* @returns
|
|
441
236
|
* @example
|
|
237
|
+
*
|
|
442
238
|
* ```ts
|
|
443
|
-
* Clerc.create()
|
|
444
|
-
* .version("1.0.0")
|
|
239
|
+
* Clerc.create().version("1.0.0");
|
|
445
240
|
* ```
|
|
241
|
+
*
|
|
242
|
+
* @param version
|
|
243
|
+
* @returns
|
|
446
244
|
*/
|
|
447
245
|
version(version: string): this;
|
|
448
246
|
/**
|
|
449
|
-
* Set the Locale
|
|
450
|
-
*
|
|
247
|
+
* Set the Locale You must call this method once after you created the Clerc
|
|
248
|
+
* instance.
|
|
451
249
|
*
|
|
452
|
-
* @param locale
|
|
453
|
-
* @returns
|
|
454
250
|
* @example
|
|
251
|
+
*
|
|
455
252
|
* ```ts
|
|
456
253
|
* Clerc.create()
|
|
457
254
|
* .locale("en")
|
|
458
255
|
* .command(...)
|
|
459
256
|
* ```
|
|
257
|
+
*
|
|
258
|
+
* @param locale
|
|
259
|
+
* @returns
|
|
460
260
|
*/
|
|
461
261
|
locale(locale: string): this;
|
|
462
262
|
/**
|
|
463
|
-
* Set the fallback Locale
|
|
464
|
-
*
|
|
263
|
+
* Set the fallback Locale You must call this method once after you created
|
|
264
|
+
* the Clerc instance.
|
|
465
265
|
*
|
|
466
|
-
* @param fallbackLocale
|
|
467
|
-
* @returns
|
|
468
266
|
* @example
|
|
267
|
+
*
|
|
469
268
|
* ```ts
|
|
470
269
|
* Clerc.create()
|
|
471
270
|
* .fallbackLocale("en")
|
|
472
271
|
* .command(...)
|
|
473
272
|
* ```
|
|
273
|
+
*
|
|
274
|
+
* @param fallbackLocale
|
|
275
|
+
* @returns
|
|
474
276
|
*/
|
|
475
277
|
fallbackLocale(fallbackLocale: string): this;
|
|
476
278
|
/**
|
|
477
279
|
* Register a error handler
|
|
478
280
|
*
|
|
479
|
-
* @param handler
|
|
480
|
-
* @returns
|
|
481
281
|
* @example
|
|
282
|
+
*
|
|
482
283
|
* ```ts
|
|
483
|
-
* Clerc.create()
|
|
484
|
-
*
|
|
284
|
+
* Clerc.create().errorHandler((err) => {
|
|
285
|
+
* console.log(err);
|
|
286
|
+
* });
|
|
485
287
|
* ```
|
|
288
|
+
*
|
|
289
|
+
* @param handler
|
|
290
|
+
* @returns
|
|
486
291
|
*/
|
|
487
292
|
errorHandler(handler: (err: any) => void): this;
|
|
488
293
|
/**
|
|
489
294
|
* Register a command
|
|
490
295
|
*
|
|
491
|
-
* @param name
|
|
492
|
-
* @param description
|
|
493
|
-
* @param options
|
|
494
|
-
* @returns
|
|
495
296
|
* @example
|
|
297
|
+
*
|
|
496
298
|
* ```ts
|
|
497
|
-
* Clerc.create()
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
* })
|
|
299
|
+
* Clerc.create().command("test", "test command", {
|
|
300
|
+
* alias: "t",
|
|
301
|
+
* flags: {
|
|
302
|
+
* foo: {
|
|
303
|
+
* alias: "f",
|
|
304
|
+
* description: "foo flag",
|
|
305
|
+
* },
|
|
306
|
+
* },
|
|
307
|
+
* });
|
|
507
308
|
* ```
|
|
309
|
+
*
|
|
508
310
|
* @example
|
|
311
|
+
*
|
|
509
312
|
* ```ts
|
|
510
|
-
* Clerc.create()
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
* })
|
|
313
|
+
* Clerc.create().command("", "root", {
|
|
314
|
+
* flags: {
|
|
315
|
+
* foo: {
|
|
316
|
+
* alias: "f",
|
|
317
|
+
* description: "foo flag",
|
|
318
|
+
* },
|
|
319
|
+
* },
|
|
320
|
+
* });
|
|
519
321
|
* ```
|
|
322
|
+
*
|
|
323
|
+
* @param name
|
|
324
|
+
* @param description
|
|
325
|
+
* @param options
|
|
326
|
+
* @returns
|
|
520
327
|
*/
|
|
521
328
|
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>;
|
|
522
329
|
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>;
|
|
523
330
|
/**
|
|
524
331
|
* Register a global flag
|
|
525
332
|
*
|
|
333
|
+
* @example
|
|
334
|
+
*
|
|
335
|
+
* ```ts
|
|
336
|
+
* Clerc.create().flag("help", "help", {
|
|
337
|
+
* alias: "h",
|
|
338
|
+
* type: Boolean,
|
|
339
|
+
* });
|
|
340
|
+
* ```
|
|
341
|
+
*
|
|
526
342
|
* @param name
|
|
527
343
|
* @param description
|
|
528
344
|
* @param options
|
|
529
345
|
* @returns
|
|
530
|
-
* @example
|
|
531
|
-
* ```ts
|
|
532
|
-
* Clerc.create()
|
|
533
|
-
* .flag("help", "help", {
|
|
534
|
-
* alias: "h",
|
|
535
|
-
* type: Boolean,
|
|
536
|
-
* })
|
|
537
|
-
* ```
|
|
538
346
|
*/
|
|
539
347
|
flag<N extends string, O extends GlobalFlagOption>(name: N, description: string, options: O): this & Clerc<C, GF & Record<N, O>>;
|
|
540
348
|
/**
|
|
541
349
|
* Register a handler
|
|
542
350
|
*
|
|
543
|
-
* @param name
|
|
544
|
-
* @param handler
|
|
545
|
-
* @returns
|
|
546
351
|
* @example
|
|
352
|
+
*
|
|
547
353
|
* ```ts
|
|
548
354
|
* Clerc.create()
|
|
549
355
|
* .command("test", "test command")
|
|
550
356
|
* .on("test", (ctx) => {
|
|
551
357
|
* console.log(ctx);
|
|
552
|
-
* })
|
|
358
|
+
* });
|
|
553
359
|
* ```
|
|
360
|
+
*
|
|
361
|
+
* @param name
|
|
362
|
+
* @param handler
|
|
363
|
+
* @returns
|
|
554
364
|
*/
|
|
555
365
|
on<K extends LiteralUnion<keyof CM, string | RootType>, CM extends this["_commands"] = this["_commands"]>(name: K, handler: Handler<CM, K, this["_flags"]>): this;
|
|
556
366
|
/**
|
|
557
367
|
* Use a plugin
|
|
558
368
|
*
|
|
559
|
-
* @param plugin
|
|
560
|
-
* @returns
|
|
561
369
|
* @example
|
|
370
|
+
*
|
|
562
371
|
* ```ts
|
|
563
|
-
* Clerc.create()
|
|
564
|
-
* .use(plugin)
|
|
372
|
+
* Clerc.create().use(plugin);
|
|
565
373
|
* ```
|
|
374
|
+
*
|
|
375
|
+
* @param plugin
|
|
376
|
+
* @returns
|
|
566
377
|
*/
|
|
567
378
|
use<T extends Clerc, U extends Clerc>(plugin: Plugin<T, U>): this & Clerc<C & U["_commands"]> & U;
|
|
568
379
|
/**
|
|
569
380
|
* Register a inspector
|
|
570
381
|
*
|
|
571
|
-
* @param inspector
|
|
572
|
-
* @returns
|
|
573
382
|
* @example
|
|
383
|
+
*
|
|
574
384
|
* ```ts
|
|
575
|
-
* Clerc.create()
|
|
576
|
-
* .
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
* })
|
|
385
|
+
* Clerc.create().inspector((ctx, next) => {
|
|
386
|
+
* console.log(ctx);
|
|
387
|
+
* next();
|
|
388
|
+
* });
|
|
580
389
|
* ```
|
|
390
|
+
*
|
|
391
|
+
* @param inspector
|
|
392
|
+
* @returns
|
|
581
393
|
*/
|
|
582
394
|
inspector(inspector: Inspector): this;
|
|
583
395
|
/**
|
|
584
396
|
* Parse the command line arguments
|
|
585
397
|
*
|
|
586
|
-
* @param args
|
|
587
|
-
* @param optionsOrArgv
|
|
588
|
-
* @returns
|
|
589
398
|
* @example
|
|
399
|
+
*
|
|
590
400
|
* ```ts
|
|
591
|
-
* Clerc.create()
|
|
592
|
-
* .parse(process.argv.slice(2)) // Optional
|
|
401
|
+
* Clerc.create().parse(process.argv.slice(2)); // Optional
|
|
593
402
|
* ```
|
|
403
|
+
*
|
|
404
|
+
* @param args
|
|
405
|
+
* @param optionsOrArgv
|
|
406
|
+
* @returns
|
|
594
407
|
*/
|
|
595
408
|
parse(optionsOrArgv?: string[] | ParseOptions): this;
|
|
596
409
|
/**
|
|
597
410
|
* Run matched command
|
|
598
411
|
*
|
|
599
|
-
* @returns
|
|
600
412
|
* @example
|
|
413
|
+
*
|
|
601
414
|
* ```ts
|
|
602
|
-
* Clerc.create()
|
|
603
|
-
* .parse({ run: false })
|
|
604
|
-
* .runMatchedCommand()
|
|
415
|
+
* Clerc.create().parse({ run: false }).runMatchedCommand();
|
|
605
416
|
* ```
|
|
417
|
+
*
|
|
418
|
+
* @returns
|
|
606
419
|
*/
|
|
607
420
|
runMatchedCommand(): this;
|
|
608
421
|
}
|
|
@@ -623,7 +436,7 @@ declare class CommandNameConflictError extends Error {
|
|
|
623
436
|
n2: string;
|
|
624
437
|
constructor(n1: string, n2: string, t: TranslateFn);
|
|
625
438
|
}
|
|
626
|
-
declare class
|
|
439
|
+
declare class ScriptNameNotSetError extends Error {
|
|
627
440
|
constructor(t: TranslateFn);
|
|
628
441
|
}
|
|
629
442
|
declare class DescriptionNotSetError extends Error {
|
|
@@ -657,4 +470,4 @@ declare const formatCommandName: (name: string | string[] | RootType) => string;
|
|
|
657
470
|
declare const detectLocale: () => string;
|
|
658
471
|
declare const stripFlags: (argv: string[]) => string[];
|
|
659
472
|
|
|
660
|
-
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap,
|
|
473
|
+
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, ScriptNameNotSetError, TranslateFn, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, isValidName, resolveArgv, resolveCommand, resolveFlattenCommands, stripFlags, withBrackets };
|