clerc 0.3.3 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clerc",
3
- "version": "0.3.3",
3
+ "version": "0.4.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,6 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
+ "@clerc/utils": "0.4.0",
42
43
  "is-platform": "^0.2.0",
43
44
  "lite-emit": "^1.4.0",
44
45
  "mri": "^1.2.0",
package/dist/index.cjs DELETED
@@ -1,172 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var liteEmit = require('lite-emit');
6
- var mri = require('mri');
7
- var typeFlag = require('type-flag');
8
- var isPlatform = require('is-platform');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- var mri__default = /*#__PURE__*/_interopDefaultLegacy(mri);
13
-
14
- class SingleCommandError extends Error {
15
- }
16
- class CommandExistsError extends Error {
17
- }
18
- class CommonCommandExistsError extends Error {
19
- }
20
- class NoSuchCommandError extends Error {
21
- }
22
-
23
- const mustArray = (a) => Array.isArray(a) ? a : [a];
24
- const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
25
- const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
26
- const resolveFlagAlias = (_command) => Object.entries((_command == null ? void 0 : _command.flags) || {}).reduce((acc, [name, command]) => {
27
- if (command.alias) {
28
- const item = mustArray(command.alias).map(kebabCase);
29
- acc[kebabCase(name)] = item;
30
- }
31
- return acc;
32
- }, {});
33
- const resolveFlagDefault = (_command) => Object.entries((_command == null ? void 0 : _command.flags) || {}).reduce((acc, [name, command]) => {
34
- const item = command.default;
35
- if (item) {
36
- acc[name] = item;
37
- }
38
- return acc;
39
- }, {});
40
- function resolveCommand(commands, name) {
41
- if (name === SingleCommand) {
42
- return commands[SingleCommand];
43
- }
44
- const possibleCommands = Object.values(commands).filter(
45
- (c) => c.name === name || mustArray(c.alias || []).map(String).includes(name)
46
- );
47
- if (possibleCommands.length > 1) {
48
- throw new Error(`Multiple commands found with name "${name}"`);
49
- }
50
- return possibleCommands[0];
51
- }
52
- const resolveArgv = () => isPlatform.isNode() ? process.argv.slice(2) : isPlatform.isDeno() ? Deno.args : [];
53
- function compose(inspectors) {
54
- return (ctx) => {
55
- return dispatch(0);
56
- function dispatch(i) {
57
- const inspector = inspectors[i];
58
- return inspector(ctx, dispatch.bind(null, i + 1));
59
- }
60
- };
61
- }
62
-
63
- const SingleCommand = Symbol("SingleCommand");
64
- class Clerc {
65
- constructor() {
66
- this._name = "";
67
- this._description = "";
68
- this._version = "";
69
- this._inspectors = [];
70
- this._commands = {};
71
- this.__commandEmitter = new liteEmit.LiteEmit();
72
- }
73
- get __isSingleCommand() {
74
- return this._commands[SingleCommand] !== void 0;
75
- }
76
- get __hasCommands() {
77
- return Object.keys(this._commands).length > 0;
78
- }
79
- static create() {
80
- return new Clerc();
81
- }
82
- name(name) {
83
- this._name = name;
84
- return this;
85
- }
86
- description(description) {
87
- this._description = description;
88
- return this;
89
- }
90
- version(version) {
91
- this._version = version;
92
- return this;
93
- }
94
- command(name, description, options = {}) {
95
- if (this._commands[name]) {
96
- if (name === SingleCommand) {
97
- throw new CommandExistsError("Single command already exists");
98
- }
99
- throw new CommandExistsError(`Command "${name === SingleCommand ? "[SingleCommand]" : name}" already exists`);
100
- }
101
- if (this.__isSingleCommand) {
102
- throw new SingleCommandError("Single command mode enabled");
103
- }
104
- if (name === SingleCommand && this.__hasCommands) {
105
- throw new CommonCommandExistsError("Common command exists");
106
- }
107
- const { alias, flags } = options;
108
- this._commands[name] = { name, description, alias, flags };
109
- return this;
110
- }
111
- on(name, handler) {
112
- this.__commandEmitter.on(name, handler);
113
- return this;
114
- }
115
- use(plugin) {
116
- return plugin.setup(this);
117
- }
118
- inspector(inspector) {
119
- this._inspectors.push(inspector);
120
- return this;
121
- }
122
- parse(argv = resolveArgv()) {
123
- const parsed = mri__default["default"](argv);
124
- const name = String(parsed._[0]);
125
- const command = this.__isSingleCommand ? this._commands[SingleCommand] : resolveCommand(this._commands, name);
126
- const isCommandResolved = !!command;
127
- const parsedWithType = typeFlag.typeFlag((command == null ? void 0 : command.flags) || {}, argv);
128
- const { _: args, flags } = parsedWithType;
129
- const parameters = this.__isSingleCommand || !isCommandResolved ? args : args.slice(1);
130
- const inspectorContext = {
131
- name: command == null ? void 0 : command.name,
132
- resolved: isCommandResolved,
133
- isSingleCommand: this.__isSingleCommand,
134
- raw: parsedWithType,
135
- parameters,
136
- flags,
137
- cli: this
138
- };
139
- const handlerContext = inspectorContext;
140
- const emitHandler = () => {
141
- if (!command) {
142
- throw new NoSuchCommandError(`No such command: ${name}`);
143
- }
144
- this.__commandEmitter.emit(command.name, handlerContext);
145
- };
146
- const inspectors = [...this._inspectors, emitHandler];
147
- const inspector = compose(inspectors);
148
- inspector(inspectorContext);
149
- }
150
- }
151
-
152
- const definePlugin = (p) => p;
153
- const defineHandler = (_cli, _key, handler) => handler;
154
- const defineInspector = (_cli, inspector) => inspector;
155
-
156
- exports.Clerc = Clerc;
157
- exports.CommandExistsError = CommandExistsError;
158
- exports.CommonCommandExistsError = CommonCommandExistsError;
159
- exports.NoSuchCommandError = NoSuchCommandError;
160
- exports.SingleCommand = SingleCommand;
161
- exports.SingleCommandError = SingleCommandError;
162
- exports.camelCase = camelCase;
163
- exports.compose = compose;
164
- exports.defineHandler = defineHandler;
165
- exports.defineInspector = defineInspector;
166
- exports.definePlugin = definePlugin;
167
- exports.kebabCase = kebabCase;
168
- exports.mustArray = mustArray;
169
- exports.resolveArgv = resolveArgv;
170
- exports.resolveCommand = resolveCommand;
171
- exports.resolveFlagAlias = resolveFlagAlias;
172
- exports.resolveFlagDefault = resolveFlagDefault;
package/dist/index.d.ts DELETED
@@ -1,290 +0,0 @@
1
- declare const DOUBLE_DASH = "--";
2
- declare type TypeFunction<ReturnType = any> = (value: any) => ReturnType;
3
- declare type TypeFunctionArray<ReturnType> = readonly [TypeFunction<ReturnType>];
4
- declare type FlagType<ReturnType = any> = TypeFunction<ReturnType> | TypeFunctionArray<ReturnType>;
5
- declare type FlagSchemaBase<TF> = {
6
- /**
7
- Type of the flag as a function that parses the argv string and returns the parsed value.
8
-
9
- @example
10
- ```
11
- type: String
12
- ```
13
-
14
- @example Wrap in an array to accept multiple values.
15
- ```
16
- type: [Boolean]
17
- ```
18
-
19
- @example Custom function type that uses moment.js to parse string as date.
20
- ```
21
- type: function CustomDate(value: string) {
22
- return moment(value).toDate();
23
- }
24
- ```
25
- */
26
- type: TF;
27
- /**
28
- A single-character alias for the flag.
29
-
30
- @example
31
- ```
32
- alias: 's'
33
- ```
34
- */
35
- alias?: string;
36
- } & Record<PropertyKey, unknown>;
37
- declare type FlagSchemaDefault<TF, DefaultType = any> = FlagSchemaBase<TF> & {
38
- /**
39
- Default value of the flag. Also accepts a function that returns the default value.
40
- [Default: undefined]
41
-
42
- @example
43
- ```
44
- default: 'hello'
45
- ```
46
-
47
- @example
48
- ```
49
- default: () => [1, 2, 3]
50
- ```
51
- */
52
- default: DefaultType | (() => DefaultType);
53
- };
54
- declare type FlagSchema<TF = FlagType> = (FlagSchemaBase<TF> | FlagSchemaDefault<TF>);
55
- declare type FlagTypeOrSchema<ExtraOptions = Record<string, unknown>> = FlagType | (FlagSchema & ExtraOptions);
56
- declare type Flags<ExtraOptions = Record<string, unknown>> = Record<string, FlagTypeOrSchema<ExtraOptions>>;
57
- declare 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));
58
- interface ParsedFlags<Schemas = Record<string, unknown>> {
59
- flags: Schemas;
60
- unknownFlags: Record<string, (string | boolean)[]>;
61
- _: string[] & {
62
- [DOUBLE_DASH]: string[];
63
- };
64
- }
65
- declare type TypeFlag<Schemas extends Flags> = ParsedFlags<{
66
- [flag in keyof Schemas]: InferFlagType<Schemas[flag]>;
67
- }>;
68
-
69
- /**
70
- * Copied from type-fest
71
- */
72
- declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
73
- /**
74
- * Copied from type-fest
75
- */
76
- declare type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
77
- declare type Dict<T> = Record<string, T>;
78
- declare type MustArray<T> = T extends any[] ? T : [T];
79
- declare type MaybeArray<T> = T | T[];
80
- declare type GetLength<T extends any[]> = T extends {
81
- length: infer L extends number;
82
- } ? L : never;
83
- declare type GetTail<T extends any[]> = T extends [infer _Head, ...infer Tail] ? Tail : never;
84
- declare type EnhanceSingle<T, E extends Dict<any>> = T & E;
85
- declare type Enhance<T, E extends Dict<any> | Dict<any>[]> = GetLength<MustArray<E>> extends 0 ? T : Enhance<EnhanceSingle<T, MustArray<E>[0]>, GetTail<MustArray<E>>>;
86
- declare type FlagOptions = FlagSchema & {
87
- description: string;
88
- required?: boolean;
89
- };
90
- declare type Flag = FlagOptions & {
91
- name: string;
92
- };
93
- interface CommandOptions<A extends MaybeArray<string> = MaybeArray<string>, F extends Dict<FlagOptions> = Dict<FlagOptions>> {
94
- alias?: A;
95
- flags?: F;
96
- }
97
- declare type Command<N extends string | SingleCommandType = string, D extends string = string, Options extends CommandOptions = CommandOptions> = Options & {
98
- name: N;
99
- description: D;
100
- };
101
- declare type CommandRecord = Dict<Command> & {
102
- [SingleCommand]?: Command;
103
- };
104
- declare type MakeEventMap<T extends CommandRecord> = {
105
- [K in keyof T]: [InspectorContext];
106
- };
107
- declare type PossibleInputKind = string | number | boolean | Dict<any>;
108
- declare type NonNullableFlag<T extends Dict<FlagOptions> | undefined> = T extends undefined ? {} : NonNullable<T>;
109
- interface HandlerContext<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> {
110
- name?: N;
111
- resolved: boolean;
112
- isSingleCommand: boolean;
113
- raw: ParsedFlags;
114
- parameters: PossibleInputKind[];
115
- flags: TypeFlag<NonNullableFlag<C[N]["flags"]>>["flags"];
116
- cli: Clerc<C>;
117
- }
118
- declare type Handler<C extends CommandRecord = CommandRecord, K extends keyof C = keyof C> = (ctx: HandlerContext<C, K>) => void;
119
- declare type FallbackType<T, U> = {} extends T ? U : T;
120
- declare type InspectorContext<C extends CommandRecord = CommandRecord> = HandlerContext<C> & {
121
- flags: FallbackType<TypeFlag<NonNullableFlag<C[keyof C]["flags"]>>["flags"], Dict<any>>;
122
- };
123
- declare type Inspector<C extends CommandRecord = CommandRecord> = (ctx: InspectorContext<C>, next: () => void) => void;
124
- interface Plugin<T extends Clerc = Clerc, U extends Clerc = Clerc> {
125
- setup: (cli: T) => U;
126
- }
127
-
128
- declare const SingleCommand: unique symbol;
129
- declare type SingleCommandType = typeof SingleCommand;
130
- declare class Clerc<C extends CommandRecord = {}> {
131
- _name: string;
132
- _description: string;
133
- _version: string;
134
- _inspectors: Inspector[];
135
- _commands: C;
136
- private __commandEmitter;
137
- private constructor();
138
- private get __isSingleCommand();
139
- private get __hasCommands();
140
- /**
141
- * Create a new cli
142
- * @returns
143
- * @example
144
- * ```ts
145
- * const cli = Clerc.create()
146
- * ```
147
- */
148
- static create(): Clerc<{}>;
149
- /**
150
- * Set the name of the cli
151
- * @param name
152
- * @returns
153
- * @example
154
- * ```ts
155
- * Clerc.create()
156
- * .name("test")
157
- * ```
158
- */
159
- name(name: string): this;
160
- /**
161
- * Set the description of the cli
162
- * @param description
163
- * @returns
164
- * @example
165
- * ```ts
166
- * Clerc.create()
167
- * .description("test cli")
168
- */
169
- description(description: string): this;
170
- /**
171
- * Set the version of the cli
172
- * @param version
173
- * @returns
174
- * @example
175
- * ```ts
176
- * Clerc.create()
177
- * .version("1.0.0")
178
- */
179
- version(version: string): this;
180
- /**
181
- * Register a command
182
- * @param name
183
- * @param description
184
- * @param options
185
- * @returns
186
- * @example
187
- * ```ts
188
- * Clerc.create()
189
- * .command("test", "test command", {
190
- * alias: "t",
191
- * flags: {
192
- * foo: {
193
- * alias: "f",
194
- * description: "foo flag",
195
- * }
196
- * }
197
- * })
198
- * ```
199
- * @example
200
- * ```ts
201
- * Clerc.create()
202
- * .command("", "single command", {
203
- * flags: {
204
- * foo: {
205
- * alias: "f",
206
- * description: "foo flag",
207
- * }
208
- * }
209
- * })
210
- * ```
211
- */
212
- command<N extends string | SingleCommandType, D extends string, O extends CommandOptions>(name: N, description: D, options?: O): this & Clerc<C & Record<N, Command<N, D, O>>>;
213
- /**
214
- * Register a handler
215
- * @param name
216
- * @param handler
217
- * @returns
218
- * @example
219
- * ```ts
220
- * Clerc.create()
221
- * .command("test", "test command")
222
- * .on("test", (ctx) => {
223
- * console.log(ctx);
224
- * })
225
- * ```
226
- */
227
- on<K extends keyof CM, CM extends this["_commands"] = this["_commands"]>(name: LiteralUnion<K, string>, handler: Handler<CM, K>): this;
228
- /**
229
- * Use a plugin
230
- * @param plugin
231
- * @returns
232
- * @example
233
- * ```ts
234
- * Clerc.create()
235
- * .use(plugin)
236
- * ```
237
- */
238
- use<T extends Clerc, U extends Clerc>(plugin: Plugin<T, U>): U;
239
- /**
240
- * Register a inspector
241
- * @param inspector
242
- * @returns
243
- * @example
244
- * ```ts
245
- * Clerc.create()
246
- * .inspector((ctx, next) => {
247
- * console.log(ctx);
248
- * next();
249
- * })
250
- * ```
251
- */
252
- inspector(inspector: Inspector): this;
253
- /**
254
- * Parse the command line arguments
255
- * @param args
256
- * @returns
257
- * @example
258
- * ```ts
259
- * Clerc.create()
260
- * .parse(process.argv.slice(2)) // Optional
261
- * ```
262
- */
263
- parse(argv?: string[]): void;
264
- }
265
-
266
- declare const definePlugin: <T extends Clerc<{}>, U extends Clerc<{}>>(p: Plugin<T, U>) => Plugin<T, U>;
267
- 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
- declare const defineInspector: <C extends Clerc<{}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
269
-
270
- declare class SingleCommandError extends Error {
271
- }
272
- declare class CommandExistsError extends Error {
273
- }
274
- declare class CommonCommandExistsError extends Error {
275
- }
276
- declare class NoSuchCommandError extends Error {
277
- }
278
-
279
- declare const mustArray: <T>(a: MaybeArray<T>) => T[];
280
- declare type CamelCase<T extends string> = T extends `${infer A}-${infer B}${infer C}` ? `${A}${Capitalize<B>}${CamelCase<C>}` : T;
281
- declare const camelCase: <T extends string>(s: T) => CamelCase<T>;
282
- declare type KebabCase<T extends string, A extends string = ""> = T extends `${infer F}${infer R}` ? KebabCase<R, `${A}${F extends Lowercase<F> ? "" : "-"}${Lowercase<F>}`> : A;
283
- declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
284
- declare const resolveFlagAlias: (_command: Command) => Dict<string[]>;
285
- declare const resolveFlagDefault: (_command: Command) => Dict<any>;
286
- declare function resolveCommand(commands: CommandRecord, name: string | SingleCommandType): Command | undefined;
287
- declare const resolveArgv: () => string[];
288
- declare function compose(inspectors: Inspector[]): (ctx: InspectorContext) => void;
289
-
290
- export { CamelCase, Clerc, Command, CommandExistsError, CommandOptions, CommandRecord, CommonCommandExistsError, Dict, Enhance, FallbackType, Flag, FlagOptions, Handler, HandlerContext, Inspector, InspectorContext, KebabCase, LiteralUnion, MakeEventMap, MaybeArray, NoSuchCommandError, Plugin, PossibleInputKind, Primitive, SingleCommand, SingleCommandError, SingleCommandType, camelCase, compose, defineHandler, defineInspector, definePlugin, kebabCase, mustArray, resolveArgv, resolveCommand, resolveFlagAlias, resolveFlagDefault };
package/dist/index.mjs DELETED
@@ -1,148 +0,0 @@
1
- import { LiteEmit } from 'lite-emit';
2
- import mri from 'mri';
3
- import { typeFlag } from 'type-flag';
4
- import { isNode, isDeno } from 'is-platform';
5
-
6
- class SingleCommandError extends Error {
7
- }
8
- class CommandExistsError extends Error {
9
- }
10
- class CommonCommandExistsError extends Error {
11
- }
12
- class NoSuchCommandError extends Error {
13
- }
14
-
15
- const mustArray = (a) => Array.isArray(a) ? a : [a];
16
- const camelCase = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
17
- const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
18
- const resolveFlagAlias = (_command) => Object.entries((_command == null ? void 0 : _command.flags) || {}).reduce((acc, [name, command]) => {
19
- if (command.alias) {
20
- const item = mustArray(command.alias).map(kebabCase);
21
- acc[kebabCase(name)] = item;
22
- }
23
- return acc;
24
- }, {});
25
- const resolveFlagDefault = (_command) => Object.entries((_command == null ? void 0 : _command.flags) || {}).reduce((acc, [name, command]) => {
26
- const item = command.default;
27
- if (item) {
28
- acc[name] = item;
29
- }
30
- return acc;
31
- }, {});
32
- function resolveCommand(commands, name) {
33
- if (name === SingleCommand) {
34
- return commands[SingleCommand];
35
- }
36
- const possibleCommands = Object.values(commands).filter(
37
- (c) => c.name === name || mustArray(c.alias || []).map(String).includes(name)
38
- );
39
- if (possibleCommands.length > 1) {
40
- throw new Error(`Multiple commands found with name "${name}"`);
41
- }
42
- return possibleCommands[0];
43
- }
44
- const resolveArgv = () => isNode() ? process.argv.slice(2) : isDeno() ? Deno.args : [];
45
- function compose(inspectors) {
46
- return (ctx) => {
47
- return dispatch(0);
48
- function dispatch(i) {
49
- const inspector = inspectors[i];
50
- return inspector(ctx, dispatch.bind(null, i + 1));
51
- }
52
- };
53
- }
54
-
55
- const SingleCommand = Symbol("SingleCommand");
56
- class Clerc {
57
- constructor() {
58
- this._name = "";
59
- this._description = "";
60
- this._version = "";
61
- this._inspectors = [];
62
- this._commands = {};
63
- this.__commandEmitter = new LiteEmit();
64
- }
65
- get __isSingleCommand() {
66
- return this._commands[SingleCommand] !== void 0;
67
- }
68
- get __hasCommands() {
69
- return Object.keys(this._commands).length > 0;
70
- }
71
- static create() {
72
- return new Clerc();
73
- }
74
- name(name) {
75
- this._name = name;
76
- return this;
77
- }
78
- description(description) {
79
- this._description = description;
80
- return this;
81
- }
82
- version(version) {
83
- this._version = version;
84
- return this;
85
- }
86
- command(name, description, options = {}) {
87
- if (this._commands[name]) {
88
- if (name === SingleCommand) {
89
- throw new CommandExistsError("Single command already exists");
90
- }
91
- throw new CommandExistsError(`Command "${name === SingleCommand ? "[SingleCommand]" : name}" already exists`);
92
- }
93
- if (this.__isSingleCommand) {
94
- throw new SingleCommandError("Single command mode enabled");
95
- }
96
- if (name === SingleCommand && this.__hasCommands) {
97
- throw new CommonCommandExistsError("Common command exists");
98
- }
99
- const { alias, flags } = options;
100
- this._commands[name] = { name, description, alias, flags };
101
- return this;
102
- }
103
- on(name, handler) {
104
- this.__commandEmitter.on(name, handler);
105
- return this;
106
- }
107
- use(plugin) {
108
- return plugin.setup(this);
109
- }
110
- inspector(inspector) {
111
- this._inspectors.push(inspector);
112
- return this;
113
- }
114
- parse(argv = resolveArgv()) {
115
- const parsed = mri(argv);
116
- const name = String(parsed._[0]);
117
- const command = this.__isSingleCommand ? this._commands[SingleCommand] : resolveCommand(this._commands, name);
118
- const isCommandResolved = !!command;
119
- const parsedWithType = typeFlag((command == null ? void 0 : command.flags) || {}, argv);
120
- const { _: args, flags } = parsedWithType;
121
- const parameters = this.__isSingleCommand || !isCommandResolved ? args : args.slice(1);
122
- const inspectorContext = {
123
- name: command == null ? void 0 : command.name,
124
- resolved: isCommandResolved,
125
- isSingleCommand: this.__isSingleCommand,
126
- raw: parsedWithType,
127
- parameters,
128
- flags,
129
- cli: this
130
- };
131
- const handlerContext = inspectorContext;
132
- const emitHandler = () => {
133
- if (!command) {
134
- throw new NoSuchCommandError(`No such command: ${name}`);
135
- }
136
- this.__commandEmitter.emit(command.name, handlerContext);
137
- };
138
- const inspectors = [...this._inspectors, emitHandler];
139
- const inspector = compose(inspectors);
140
- inspector(inspectorContext);
141
- }
142
- }
143
-
144
- const definePlugin = (p) => p;
145
- const defineHandler = (_cli, _key, handler) => handler;
146
- const defineInspector = (_cli, inspector) => inspector;
147
-
148
- export { Clerc, CommandExistsError, CommonCommandExistsError, NoSuchCommandError, SingleCommand, SingleCommandError, camelCase, compose, defineHandler, defineInspector, definePlugin, kebabCase, mustArray, resolveArgv, resolveCommand, resolveFlagAlias, resolveFlagDefault };