clerc 0.7.0 → 0.8.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.cjs +2 -2
- package/dist/index.d.ts +15 -13
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -336,8 +336,8 @@ const _Clerc = class {
|
|
|
336
336
|
__privateGet(this, _commandEmitter).emit(command.name, handlerContext);
|
|
337
337
|
};
|
|
338
338
|
const inspectors = [...__privateGet(this, _inspectors), emitHandler];
|
|
339
|
-
const
|
|
340
|
-
|
|
339
|
+
const callInspector = compose(inspectors);
|
|
340
|
+
callInspector(getContext);
|
|
341
341
|
return this;
|
|
342
342
|
}
|
|
343
343
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -76,19 +76,21 @@ type FlagOptions = FlagSchema & {
|
|
|
76
76
|
type Flag = FlagOptions & {
|
|
77
77
|
name: string;
|
|
78
78
|
};
|
|
79
|
-
interface
|
|
79
|
+
declare interface CommandCustomProperties {
|
|
80
|
+
}
|
|
81
|
+
interface CommandOptions<P extends string[] = string[], A extends MaybeArray<string> = MaybeArray<string>, F extends Dict<FlagOptions> = Dict<FlagOptions>> extends CommandCustomProperties {
|
|
80
82
|
alias?: A;
|
|
81
83
|
parameters?: P;
|
|
82
84
|
flags?: F;
|
|
83
85
|
examples?: [string, string][];
|
|
84
86
|
notes?: string[];
|
|
85
87
|
}
|
|
86
|
-
type Command<N extends string | SingleCommandType = string,
|
|
88
|
+
type Command<N extends string | SingleCommandType = string, O extends CommandOptions = CommandOptions> = O & {
|
|
87
89
|
name: N;
|
|
88
|
-
description:
|
|
90
|
+
description: string;
|
|
89
91
|
};
|
|
90
|
-
type CommandWithHandler<N extends string | SingleCommandType = string,
|
|
91
|
-
handler?: HandlerInCommand<Record<N, Command<N,
|
|
92
|
+
type CommandWithHandler<N extends string | SingleCommandType = string, O extends CommandOptions = CommandOptions> = Command<N, O> & {
|
|
93
|
+
handler?: HandlerInCommand<Record<N, Command<N, O>>, N>;
|
|
92
94
|
};
|
|
93
95
|
type StripBrackets<Parameter extends string> = (Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never);
|
|
94
96
|
type ParameterType<Parameter extends string> = (Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never);
|
|
@@ -105,7 +107,7 @@ interface HandlerContext<C extends CommandRecord = CommandRecord, N extends keyo
|
|
|
105
107
|
name?: N;
|
|
106
108
|
resolved: boolean;
|
|
107
109
|
isSingleCommand: boolean;
|
|
108
|
-
raw:
|
|
110
|
+
raw: TypeFlag<NonNullableFlag<C[N]["flags"]>>;
|
|
109
111
|
parameters: {
|
|
110
112
|
[Parameter in [...NonNullableParameters<C[N]["parameters"]>][number] as CamelCase<StripBrackets<Parameter>>]: ParameterType<Parameter>;
|
|
111
113
|
};
|
|
@@ -208,8 +210,8 @@ declare class Clerc<C extends CommandRecord = {}> {
|
|
|
208
210
|
* })
|
|
209
211
|
* ```
|
|
210
212
|
*/
|
|
211
|
-
command<N extends string | SingleCommandType,
|
|
212
|
-
command<N extends string | SingleCommandType,
|
|
213
|
+
command<N extends string | SingleCommandType, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string> = MaybeArray<string>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(c: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>): this & Clerc<C & Record<N, Command<N, O>>>;
|
|
214
|
+
command<N extends string | SingleCommandType, P extends string[], O extends CommandOptions<[...P]>>(name: N, description: string, options?: O & CommandOptions<[...P]>): this & Clerc<C & Record<N, Command<N, O>>>;
|
|
213
215
|
/**
|
|
214
216
|
* Register a handler
|
|
215
217
|
* @param name
|
|
@@ -266,8 +268,8 @@ declare class Clerc<C extends CommandRecord = {}> {
|
|
|
266
268
|
declare const definePlugin: <T extends Clerc<{}>, U extends Clerc<{}>>(p: Plugin<T, U>) => Plugin<T, U>;
|
|
267
269
|
declare const defineHandler: <C extends Clerc<{}>, K extends keyof C["_commands"]>(_cli: C, _key: K, handler: Handler<C["_commands"], K>) => Handler<C["_commands"], K>;
|
|
268
270
|
declare const defineInspector: <C extends Clerc<{}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
|
|
269
|
-
declare const defineCommand: <N extends string | typeof SingleCommand,
|
|
270
|
-
declare const defineCommandWithHandler: <N extends string | typeof SingleCommand,
|
|
271
|
+
declare const defineCommand: <N extends string | typeof SingleCommand, P extends string[], O extends CommandOptions<[...P], MaybeArray<string>, Dict<FlagOptions>>>(c: Command<N, O>) => Command<N, O>;
|
|
272
|
+
declare const defineCommandWithHandler: <N extends string | typeof SingleCommand, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string> = MaybeArray<string>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(c: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>) => CommandWithHandler<N, O & CommandOptions<[...P], A, F>>;
|
|
271
273
|
|
|
272
274
|
declare class SingleCommandError extends Error {
|
|
273
275
|
constructor();
|
|
@@ -298,8 +300,8 @@ declare class CommandNameConflictError extends Error {
|
|
|
298
300
|
}
|
|
299
301
|
|
|
300
302
|
declare function resolveCommand(commands: CommandRecord, name: string | string[] | SingleCommandType): Command | undefined;
|
|
301
|
-
declare function resolveSubcommandsByParent(commands: CommandRecord, parent: string | string[], depth?: number): Command<string,
|
|
302
|
-
declare const resolveRootCommands: (commands: CommandRecord) => Command<string,
|
|
303
|
+
declare function resolveSubcommandsByParent(commands: CommandRecord, parent: string | string[], depth?: number): Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>[];
|
|
304
|
+
declare const resolveRootCommands: (commands: CommandRecord) => Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>[];
|
|
303
305
|
declare function resolveParametersBeforeFlag(argv: string[], isSingleCommand: boolean): string[];
|
|
304
306
|
declare const resolveArgv: () => string[];
|
|
305
307
|
declare function compose(inspectors: Inspector[]): (getCtx: () => InspectorContext) => void;
|
|
@@ -312,4 +314,4 @@ interface ParsedParameter {
|
|
|
312
314
|
declare function parseParameters(parameters: string[]): ParsedParameter[];
|
|
313
315
|
declare function mapParametersToArguments(mapping: Record<string, string | string[]>, parameters: ParsedParameter[], cliArguments: string[]): undefined;
|
|
314
316
|
|
|
315
|
-
export { Clerc, Command, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandWithHandler, CommonCommandExistsError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, MakeEventMap, MultipleCommandsMatchedError, NoSuchCommandError, ParentCommandExistsError, Plugin, PossibleInputKind, SingleCommand, SingleCommandAliasError, SingleCommandError, SingleCommandType, SubcommandExistsError, compose, defineCommand, defineCommandWithHandler, defineHandler, defineInspector, definePlugin, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
|
317
|
+
export { Clerc, Command, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandWithHandler, CommonCommandExistsError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, MakeEventMap, MultipleCommandsMatchedError, NoSuchCommandError, ParentCommandExistsError, Plugin, PossibleInputKind, SingleCommand, SingleCommandAliasError, SingleCommandError, SingleCommandType, SubcommandExistsError, compose, defineCommand, defineCommandWithHandler, defineHandler, defineInspector, definePlugin, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
package/dist/index.mjs
CHANGED
|
@@ -332,8 +332,8 @@ const _Clerc = class {
|
|
|
332
332
|
__privateGet(this, _commandEmitter).emit(command.name, handlerContext);
|
|
333
333
|
};
|
|
334
334
|
const inspectors = [...__privateGet(this, _inspectors), emitHandler];
|
|
335
|
-
const
|
|
336
|
-
|
|
335
|
+
const callInspector = compose(inspectors);
|
|
336
|
+
callInspector(getContext);
|
|
337
337
|
return this;
|
|
338
338
|
}
|
|
339
339
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clerc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc is a simple and easy-to-use cli framework.",
|
|
6
6
|
"keywords": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@clerc/utils": "0.
|
|
42
|
+
"@clerc/utils": "npm:@clerc/toolkit@0.8.0",
|
|
43
43
|
"is-platform": "^0.2.0",
|
|
44
44
|
"lite-emit": "^1.4.0",
|
|
45
45
|
"type-flag": "^3.0.0"
|