@moostjs/event-cli 0.2.28 → 0.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +83 -22
- package/dist/index.d.ts +41 -4
- package/dist/index.mjs +82 -23
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -145,11 +145,22 @@ class MoostCli {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
onInit(moost) {
|
|
148
|
+
var _a;
|
|
148
149
|
this.moost = moost;
|
|
150
|
+
for (const [alias, entry] of Object.entries(this.cliHelp.getComputedAliases())) {
|
|
151
|
+
if (entry.custom) {
|
|
152
|
+
const vars = Object.keys(entry.args || {}).map(k => ':' + k).join('/');
|
|
153
|
+
const path = '/' + alias.replace(/\s+/g, '/').replace(/:/g, '\\:') + (vars ? '/' + vars : '');
|
|
154
|
+
this.cliApp.cli(path, entry.custom.fn);
|
|
155
|
+
if ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
156
|
+
entry.custom.log(`${'[36m'}(CLI-alias*)${'[32m'}${path}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
149
160
|
void this.cliApp.run();
|
|
150
161
|
}
|
|
151
162
|
bindHandler(opts) {
|
|
152
|
-
var _a, _b, _c;
|
|
163
|
+
var _a, _b, _c, _d, _e, _f;
|
|
153
164
|
let fn;
|
|
154
165
|
for (const handler of opts.handlers) {
|
|
155
166
|
if (handler.type !== 'CLI')
|
|
@@ -159,7 +170,7 @@ class MoostCli {
|
|
|
159
170
|
: typeof opts.method === 'string'
|
|
160
171
|
? opts.method
|
|
161
172
|
: '';
|
|
162
|
-
const
|
|
173
|
+
const makePath = (p) => `${opts.prefix.replace(/\s+/g, '/') || ''}/${p}`
|
|
163
174
|
.replace(/\/\/+/g, '/')
|
|
164
175
|
// avoid interpreting "cmd:tail" as "cmd/:tail"
|
|
165
176
|
.replace(/\/\\:/g, '\\:');
|
|
@@ -178,8 +189,10 @@ class MoostCli {
|
|
|
178
189
|
},
|
|
179
190
|
});
|
|
180
191
|
}
|
|
192
|
+
const targetPath = makePath(path);
|
|
181
193
|
const { getArgs, getStaticPart } = this.cliApp.cli(targetPath, fn);
|
|
182
194
|
const meta = getCliMate().read(opts.fakeInstance, opts.method);
|
|
195
|
+
const classMeta = getCliMate().read(opts.fakeInstance);
|
|
183
196
|
const args = {};
|
|
184
197
|
getArgs().forEach(a => {
|
|
185
198
|
var _a;
|
|
@@ -187,20 +200,39 @@ class MoostCli {
|
|
|
187
200
|
args[a] = (argParam === null || argParam === void 0 ? void 0 : argParam.description) || '';
|
|
188
201
|
});
|
|
189
202
|
cliCommand = getStaticPart().replace(/\//g, ' ').trim();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
203
|
+
const cliOptions = new Map();
|
|
204
|
+
[
|
|
205
|
+
...(((_c = (_b = this.opts) === null || _b === void 0 ? void 0 : _b.globalCliOptions) === null || _c === void 0 ? void 0 : _c.length) ? this.opts.globalCliOptions : []),
|
|
206
|
+
...((classMeta === null || classMeta === void 0 ? void 0 : classMeta.cliOptions) || []),
|
|
207
|
+
...(((_d = meta === null || meta === void 0 ? void 0 : meta.params) === null || _d === void 0 ? void 0 : _d.filter(param => !!param.cliParamKeys && param.cliParamKeys.length > 0).map(param => ({
|
|
194
208
|
keys: param.cliParamKeys,
|
|
195
209
|
value: typeof param.value === 'string' ? param.value : '',
|
|
196
210
|
description: param.description || '',
|
|
197
|
-
}))) || [],
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
});
|
|
201
|
-
if ((_c = this.opts) === null || _c === void 0 ? void 0 : _c.debug) {
|
|
211
|
+
}))) || []),
|
|
212
|
+
].forEach(o => cliOptions.set(o.keys[0], o));
|
|
213
|
+
if ((_e = this.opts) === null || _e === void 0 ? void 0 : _e.debug) {
|
|
202
214
|
opts.logHandler(`${'[36m'}(CLI)${'[32m'}${targetPath}`);
|
|
203
215
|
}
|
|
216
|
+
const aliases = [];
|
|
217
|
+
if (meta === null || meta === void 0 ? void 0 : meta.cliAliases) {
|
|
218
|
+
for (const alias of meta.cliAliases) {
|
|
219
|
+
const targetPath = makePath(alias);
|
|
220
|
+
const { getStaticPart } = this.cliApp.cli(targetPath, fn);
|
|
221
|
+
aliases.push(getStaticPart().replace(/\//g, ' ').trim());
|
|
222
|
+
if ((_f = this.opts) === null || _f === void 0 ? void 0 : _f.debug) {
|
|
223
|
+
opts.logHandler(`${'[36m'}(CLI-alias)${'[32m'}${targetPath}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
this.cliHelp.addEntry({
|
|
228
|
+
description: (meta === null || meta === void 0 ? void 0 : meta.description) || '',
|
|
229
|
+
command: cliCommand,
|
|
230
|
+
options: Array.from(cliOptions.values()),
|
|
231
|
+
args,
|
|
232
|
+
aliases: aliases,
|
|
233
|
+
custom: { fn, log: opts.logHandler },
|
|
234
|
+
examples: (meta === null || meta === void 0 ? void 0 : meta.cliExamples) || [],
|
|
235
|
+
});
|
|
204
236
|
}
|
|
205
237
|
}
|
|
206
238
|
}
|
|
@@ -248,6 +280,17 @@ function CliOption(...keys) {
|
|
|
248
280
|
}
|
|
249
281
|
return vals[0];
|
|
250
282
|
}, formatParams(keys).join(', ')));
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* ## Define Global CLI Option
|
|
286
|
+
* ### @ClassDecorator
|
|
287
|
+
* The option described here will appear in every command instructions
|
|
288
|
+
* @param option keys and description of CLI option
|
|
289
|
+
* @returns
|
|
290
|
+
*/
|
|
291
|
+
function CliGlobalOption(option) {
|
|
292
|
+
const mate = getCliMate();
|
|
293
|
+
return mate.decorate('cliOptions', option, true);
|
|
251
294
|
}
|
|
252
295
|
|
|
253
296
|
/**
|
|
@@ -278,6 +321,18 @@ function Cli(path) {
|
|
|
278
321
|
*/
|
|
279
322
|
function CliAlias(alias) {
|
|
280
323
|
return getCliMate().decorate('cliAliases', alias, true);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* ## Define CLI Example
|
|
327
|
+
* ### @MethodDecorator
|
|
328
|
+
*
|
|
329
|
+
* Use it to define example for Cli Help display
|
|
330
|
+
*
|
|
331
|
+
* @param path - command alias path
|
|
332
|
+
* @returns
|
|
333
|
+
*/
|
|
334
|
+
function CliExample(cmd, description) {
|
|
335
|
+
return getCliMate().decorate('cliExamples', { cmd, description }, true);
|
|
281
336
|
}
|
|
282
337
|
|
|
283
338
|
/**
|
|
@@ -309,18 +364,22 @@ const cliHelpInterceptor = (opts) => {
|
|
|
309
364
|
if ((opts === null || opts === void 0 ? void 0 : opts.helpWithArgs) || (opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd)) {
|
|
310
365
|
const { getMethod } = moost.useControllerContext();
|
|
311
366
|
if (!getMethod()) {
|
|
312
|
-
const
|
|
367
|
+
const parts = eventCli.useCliContext().store('event').get('pathParams');
|
|
313
368
|
const cliHelp = useCliHelp().getCliHelp();
|
|
314
369
|
const cmd = cliHelp.getCliName();
|
|
315
370
|
let data;
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
371
|
+
for (let i = 0; i < Math.min(parts.length, 4); i++) {
|
|
372
|
+
const pathParams = parts.slice(0, i ? -i : parts.length).join(' ');
|
|
373
|
+
try {
|
|
374
|
+
data = cliHelp.match(pathParams);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
if (opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd) {
|
|
379
|
+
const variants = cliHelp.lookup(pathParams);
|
|
380
|
+
if (variants.length) {
|
|
381
|
+
throw new Error(`Wrong command, did you mean:\n${variants.slice(0, 7).map(c => ` $ ${cmd} ${c.main.command}`).join('\n')}`);
|
|
382
|
+
}
|
|
324
383
|
}
|
|
325
384
|
}
|
|
326
385
|
}
|
|
@@ -329,8 +388,8 @@ const cliHelpInterceptor = (opts) => {
|
|
|
329
388
|
if ((opts === null || opts === void 0 ? void 0 : opts.helpWithArgs) && main.args && Object.keys(main.args).length) {
|
|
330
389
|
throw new Error(`Arguments expected: ${Object.keys(main.args).map(l => `<${l}>`).join(', ')}`);
|
|
331
390
|
}
|
|
332
|
-
else if ((opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd) && children) {
|
|
333
|
-
throw new Error(`
|
|
391
|
+
else if ((opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd) && children && children.length) {
|
|
392
|
+
throw new Error(`Wrong command, did you mean:\n${children.slice(0, 7).map(c => ` $ ${cmd} ${c.command}`).join('\n')}`);
|
|
334
393
|
}
|
|
335
394
|
}
|
|
336
395
|
}
|
|
@@ -362,6 +421,8 @@ const CliHelpInterceptor = (...opts) => moost.Intercept(cliHelpInterceptor(...op
|
|
|
362
421
|
|
|
363
422
|
exports.Cli = Cli;
|
|
364
423
|
exports.CliAlias = CliAlias;
|
|
424
|
+
exports.CliExample = CliExample;
|
|
425
|
+
exports.CliGlobalOption = CliGlobalOption;
|
|
365
426
|
exports.CliHelpInterceptor = CliHelpInterceptor;
|
|
366
427
|
exports.CliOption = CliOption;
|
|
367
428
|
exports.MoostCli = MoostCli;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { TInterceptorFn } from 'moost';
|
|
|
5
5
|
import { TMoostAdapter } from 'moost';
|
|
6
6
|
import { TMoostAdapterOptions } from 'moost';
|
|
7
7
|
import { TWooksCliOptions } from '@wooksjs/event-cli';
|
|
8
|
+
import { TWooksHandler } from 'wooks';
|
|
8
9
|
import { WooksCli } from '@wooksjs/event-cli';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -34,6 +35,30 @@ export declare function Cli(path?: string): MethodDecorator;
|
|
|
34
35
|
*/
|
|
35
36
|
export declare function CliAlias(alias: string): MethodDecorator;
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* ## Define CLI Example
|
|
40
|
+
* ### @MethodDecorator
|
|
41
|
+
*
|
|
42
|
+
* Use it to define example for Cli Help display
|
|
43
|
+
*
|
|
44
|
+
* @param path - command alias path
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
export declare function CliExample(cmd: string, description?: string): MethodDecorator;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* ## Define Global CLI Option
|
|
51
|
+
* ### @ClassDecorator
|
|
52
|
+
* The option described here will appear in every command instructions
|
|
53
|
+
* @param option keys and description of CLI option
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export declare function CliGlobalOption(option: {
|
|
57
|
+
keys: string[];
|
|
58
|
+
description?: string;
|
|
59
|
+
value?: string;
|
|
60
|
+
}): ClassDecorator;
|
|
61
|
+
|
|
37
62
|
/**
|
|
38
63
|
* ## @Decorator
|
|
39
64
|
* ### Interceptor Factory for CliHelpRenderer
|
|
@@ -113,6 +138,11 @@ export declare const cliHelpInterceptor: (opts?: {
|
|
|
113
138
|
helpWithIncompleteCmd?: boolean;
|
|
114
139
|
}) => TInterceptorFn;
|
|
115
140
|
|
|
141
|
+
declare type CliHelpRendererWithFn = CliHelpRenderer<{
|
|
142
|
+
fn: TWooksHandler;
|
|
143
|
+
log: ((eventName: string) => void);
|
|
144
|
+
}>;
|
|
145
|
+
|
|
116
146
|
/**
|
|
117
147
|
* ## Define CLI Option
|
|
118
148
|
* ### @ParameterDecorator
|
|
@@ -167,7 +197,7 @@ export declare function CliOption(...keys: string[]): ParameterDecorator;
|
|
|
167
197
|
export declare class MoostCli implements TMoostAdapter<TCliHandlerMeta> {
|
|
168
198
|
protected opts?: TMoostCliOpts | undefined;
|
|
169
199
|
protected cliApp: WooksCli;
|
|
170
|
-
protected cliHelp:
|
|
200
|
+
protected cliHelp: CliHelpRendererWithFn;
|
|
171
201
|
constructor(opts?: TMoostCliOpts | undefined);
|
|
172
202
|
onNotFound(): Promise<unknown>;
|
|
173
203
|
protected moost?: Moost;
|
|
@@ -180,7 +210,7 @@ export declare class MoostCli implements TMoostAdapter<TCliHandlerMeta> {
|
|
|
180
210
|
* Used internally to set CliHelpRenderer instance for an event state
|
|
181
211
|
* @param cliHelp CliHelpRenderer
|
|
182
212
|
*/
|
|
183
|
-
export declare function setCliHelpForEvent(cliHelp:
|
|
213
|
+
export declare function setCliHelpForEvent(cliHelp: CliHelpRendererWithFn): void;
|
|
184
214
|
|
|
185
215
|
export declare interface TCliHandlerMeta {
|
|
186
216
|
path: string;
|
|
@@ -194,11 +224,18 @@ export declare interface TMoostCliOpts {
|
|
|
194
224
|
/**
|
|
195
225
|
* CliHelpRenderer options or instance
|
|
196
226
|
*/
|
|
197
|
-
cliHelp?:
|
|
227
|
+
cliHelp?: CliHelpRendererWithFn | TCliHelpOptions;
|
|
198
228
|
/**
|
|
199
229
|
* more internal logs are printed when true
|
|
200
230
|
*/
|
|
201
231
|
debug?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Array of cli options applicable to every cli command
|
|
234
|
+
*/
|
|
235
|
+
globalCliOptions?: {
|
|
236
|
+
keys: string[];
|
|
237
|
+
description?: string;
|
|
238
|
+
}[];
|
|
202
239
|
}
|
|
203
240
|
|
|
204
241
|
/**
|
|
@@ -212,7 +249,7 @@ export declare interface TMoostCliOpts {
|
|
|
212
249
|
* @returns
|
|
213
250
|
*/
|
|
214
251
|
export declare function useCliHelp(): {
|
|
215
|
-
getCliHelp: () =>
|
|
252
|
+
getCliHelp: () => CliHelpRendererWithFn;
|
|
216
253
|
render: (width?: number, withColors?: boolean) => string[];
|
|
217
254
|
print: (withColors?: boolean) => void;
|
|
218
255
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -143,11 +143,22 @@ class MoostCli {
|
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
onInit(moost) {
|
|
146
|
+
var _a;
|
|
146
147
|
this.moost = moost;
|
|
148
|
+
for (const [alias, entry] of Object.entries(this.cliHelp.getComputedAliases())) {
|
|
149
|
+
if (entry.custom) {
|
|
150
|
+
const vars = Object.keys(entry.args || {}).map(k => ':' + k).join('/');
|
|
151
|
+
const path = '/' + alias.replace(/\s+/g, '/').replace(/:/g, '\\:') + (vars ? '/' + vars : '');
|
|
152
|
+
this.cliApp.cli(path, entry.custom.fn);
|
|
153
|
+
if ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
154
|
+
entry.custom.log(`${'[36m'}(CLI-alias*)${'[32m'}${path}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
147
158
|
void this.cliApp.run();
|
|
148
159
|
}
|
|
149
160
|
bindHandler(opts) {
|
|
150
|
-
var _a, _b, _c;
|
|
161
|
+
var _a, _b, _c, _d, _e, _f;
|
|
151
162
|
let fn;
|
|
152
163
|
for (const handler of opts.handlers) {
|
|
153
164
|
if (handler.type !== 'CLI')
|
|
@@ -157,7 +168,7 @@ class MoostCli {
|
|
|
157
168
|
: typeof opts.method === 'string'
|
|
158
169
|
? opts.method
|
|
159
170
|
: '';
|
|
160
|
-
const
|
|
171
|
+
const makePath = (p) => `${opts.prefix.replace(/\s+/g, '/') || ''}/${p}`
|
|
161
172
|
.replace(/\/\/+/g, '/')
|
|
162
173
|
// avoid interpreting "cmd:tail" as "cmd/:tail"
|
|
163
174
|
.replace(/\/\\:/g, '\\:');
|
|
@@ -176,8 +187,10 @@ class MoostCli {
|
|
|
176
187
|
},
|
|
177
188
|
});
|
|
178
189
|
}
|
|
190
|
+
const targetPath = makePath(path);
|
|
179
191
|
const { getArgs, getStaticPart } = this.cliApp.cli(targetPath, fn);
|
|
180
192
|
const meta = getCliMate().read(opts.fakeInstance, opts.method);
|
|
193
|
+
const classMeta = getCliMate().read(opts.fakeInstance);
|
|
181
194
|
const args = {};
|
|
182
195
|
getArgs().forEach(a => {
|
|
183
196
|
var _a;
|
|
@@ -185,20 +198,39 @@ class MoostCli {
|
|
|
185
198
|
args[a] = (argParam === null || argParam === void 0 ? void 0 : argParam.description) || '';
|
|
186
199
|
});
|
|
187
200
|
cliCommand = getStaticPart().replace(/\//g, ' ').trim();
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
201
|
+
const cliOptions = new Map();
|
|
202
|
+
[
|
|
203
|
+
...(((_c = (_b = this.opts) === null || _b === void 0 ? void 0 : _b.globalCliOptions) === null || _c === void 0 ? void 0 : _c.length) ? this.opts.globalCliOptions : []),
|
|
204
|
+
...((classMeta === null || classMeta === void 0 ? void 0 : classMeta.cliOptions) || []),
|
|
205
|
+
...(((_d = meta === null || meta === void 0 ? void 0 : meta.params) === null || _d === void 0 ? void 0 : _d.filter(param => !!param.cliParamKeys && param.cliParamKeys.length > 0).map(param => ({
|
|
192
206
|
keys: param.cliParamKeys,
|
|
193
207
|
value: typeof param.value === 'string' ? param.value : '',
|
|
194
208
|
description: param.description || '',
|
|
195
|
-
}))) || [],
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
if ((_c = this.opts) === null || _c === void 0 ? void 0 : _c.debug) {
|
|
209
|
+
}))) || []),
|
|
210
|
+
].forEach(o => cliOptions.set(o.keys[0], o));
|
|
211
|
+
if ((_e = this.opts) === null || _e === void 0 ? void 0 : _e.debug) {
|
|
200
212
|
opts.logHandler(`${'[36m'}(CLI)${'[32m'}${targetPath}`);
|
|
201
213
|
}
|
|
214
|
+
const aliases = [];
|
|
215
|
+
if (meta === null || meta === void 0 ? void 0 : meta.cliAliases) {
|
|
216
|
+
for (const alias of meta.cliAliases) {
|
|
217
|
+
const targetPath = makePath(alias);
|
|
218
|
+
const { getStaticPart } = this.cliApp.cli(targetPath, fn);
|
|
219
|
+
aliases.push(getStaticPart().replace(/\//g, ' ').trim());
|
|
220
|
+
if ((_f = this.opts) === null || _f === void 0 ? void 0 : _f.debug) {
|
|
221
|
+
opts.logHandler(`${'[36m'}(CLI-alias)${'[32m'}${targetPath}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
this.cliHelp.addEntry({
|
|
226
|
+
description: (meta === null || meta === void 0 ? void 0 : meta.description) || '',
|
|
227
|
+
command: cliCommand,
|
|
228
|
+
options: Array.from(cliOptions.values()),
|
|
229
|
+
args,
|
|
230
|
+
aliases: aliases,
|
|
231
|
+
custom: { fn, log: opts.logHandler },
|
|
232
|
+
examples: (meta === null || meta === void 0 ? void 0 : meta.cliExamples) || [],
|
|
233
|
+
});
|
|
202
234
|
}
|
|
203
235
|
}
|
|
204
236
|
}
|
|
@@ -246,6 +278,17 @@ function CliOption(...keys) {
|
|
|
246
278
|
}
|
|
247
279
|
return vals[0];
|
|
248
280
|
}, formatParams(keys).join(', ')));
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* ## Define Global CLI Option
|
|
284
|
+
* ### @ClassDecorator
|
|
285
|
+
* The option described here will appear in every command instructions
|
|
286
|
+
* @param option keys and description of CLI option
|
|
287
|
+
* @returns
|
|
288
|
+
*/
|
|
289
|
+
function CliGlobalOption(option) {
|
|
290
|
+
const mate = getCliMate();
|
|
291
|
+
return mate.decorate('cliOptions', option, true);
|
|
249
292
|
}
|
|
250
293
|
|
|
251
294
|
/**
|
|
@@ -276,6 +319,18 @@ function Cli(path) {
|
|
|
276
319
|
*/
|
|
277
320
|
function CliAlias(alias) {
|
|
278
321
|
return getCliMate().decorate('cliAliases', alias, true);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* ## Define CLI Example
|
|
325
|
+
* ### @MethodDecorator
|
|
326
|
+
*
|
|
327
|
+
* Use it to define example for Cli Help display
|
|
328
|
+
*
|
|
329
|
+
* @param path - command alias path
|
|
330
|
+
* @returns
|
|
331
|
+
*/
|
|
332
|
+
function CliExample(cmd, description) {
|
|
333
|
+
return getCliMate().decorate('cliExamples', { cmd, description }, true);
|
|
279
334
|
}
|
|
280
335
|
|
|
281
336
|
/**
|
|
@@ -307,18 +362,22 @@ const cliHelpInterceptor = (opts) => {
|
|
|
307
362
|
if ((opts === null || opts === void 0 ? void 0 : opts.helpWithArgs) || (opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd)) {
|
|
308
363
|
const { getMethod } = useControllerContext();
|
|
309
364
|
if (!getMethod()) {
|
|
310
|
-
const
|
|
365
|
+
const parts = useCliContext().store('event').get('pathParams');
|
|
311
366
|
const cliHelp = useCliHelp().getCliHelp();
|
|
312
367
|
const cmd = cliHelp.getCliName();
|
|
313
368
|
let data;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
369
|
+
for (let i = 0; i < Math.min(parts.length, 4); i++) {
|
|
370
|
+
const pathParams = parts.slice(0, i ? -i : parts.length).join(' ');
|
|
371
|
+
try {
|
|
372
|
+
data = cliHelp.match(pathParams);
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
catch (e) {
|
|
376
|
+
if (opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd) {
|
|
377
|
+
const variants = cliHelp.lookup(pathParams);
|
|
378
|
+
if (variants.length) {
|
|
379
|
+
throw new Error(`Wrong command, did you mean:\n${variants.slice(0, 7).map(c => ` $ ${cmd} ${c.main.command}`).join('\n')}`);
|
|
380
|
+
}
|
|
322
381
|
}
|
|
323
382
|
}
|
|
324
383
|
}
|
|
@@ -327,8 +386,8 @@ const cliHelpInterceptor = (opts) => {
|
|
|
327
386
|
if ((opts === null || opts === void 0 ? void 0 : opts.helpWithArgs) && main.args && Object.keys(main.args).length) {
|
|
328
387
|
throw new Error(`Arguments expected: ${Object.keys(main.args).map(l => `<${l}>`).join(', ')}`);
|
|
329
388
|
}
|
|
330
|
-
else if ((opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd) && children) {
|
|
331
|
-
throw new Error(`
|
|
389
|
+
else if ((opts === null || opts === void 0 ? void 0 : opts.helpWithIncompleteCmd) && children && children.length) {
|
|
390
|
+
throw new Error(`Wrong command, did you mean:\n${children.slice(0, 7).map(c => ` $ ${cmd} ${c.command}`).join('\n')}`);
|
|
332
391
|
}
|
|
333
392
|
}
|
|
334
393
|
}
|
|
@@ -358,4 +417,4 @@ const cliHelpInterceptor = (opts) => {
|
|
|
358
417
|
*/
|
|
359
418
|
const CliHelpInterceptor = (...opts) => Intercept(cliHelpInterceptor(...opts));
|
|
360
419
|
|
|
361
|
-
export { Cli, CliAlias, CliHelpInterceptor, CliOption, MoostCli, cliHelpInterceptor, setCliHelpForEvent, useCliHelp };
|
|
420
|
+
export { Cli, CliAlias, CliExample, CliGlobalOption, CliHelpInterceptor, CliOption, MoostCli, cliHelpInterceptor, setCliHelpForEvent, useCliHelp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.29",
|
|
4
4
|
"description": "@moostjs/event-cli",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-cli#readme",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"moost": "0.2.
|
|
32
|
-
"wooks": "^0.2.
|
|
33
|
-
"@wooksjs/event-core": "^0.2.
|
|
31
|
+
"moost": "0.2.29",
|
|
32
|
+
"wooks": "^0.2.23",
|
|
33
|
+
"@wooksjs/event-core": "^0.2.23"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@wooksjs/event-cli": "^0.2.
|
|
37
|
-
"@prostojs/cli-help": "^0.0.
|
|
36
|
+
"@wooksjs/event-cli": "^0.2.23",
|
|
37
|
+
"@prostojs/cli-help": "^0.0.9"
|
|
38
38
|
}
|
|
39
39
|
}
|