MCPcopy Create free account
hub / github.com/Serverless-Devs/Serverless-Devs / Help

Class Help

src/command/cli/help.ts:7–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import logger from '@/logger';
6
7class Help {
8 private raw: string[] = [];
9 private logger = logger;
10 constructor(private program: Command) {}
11 async init() {
12 const {
13 _: [, ...raw],
14 } = utils.parseArgv(process.argv.slice(2));
15 this.raw = raw;
16 if (raw.length === 1) {
17 return await this.showRaw1();
18 }
19 if (raw.length === 2) {
20 return await this.showRaw2();
21 }
22 return await this.showRaw3();
23 }
24 async showRaw1() {
25 const [componentName] = this.raw;
26 const componentCommand = this.program.command(componentName).allowUnknownOption();
27 const instance = await loadComponent(componentName, { logger: this.logger.loggerInstance.__generate(componentName) });
28 each(get(instance, 'commands'), (item, key) => {
29 const desc = get(item, 'help.description');
30 const subCommand = componentCommand
31 .command(key)
32 .description(desc)
33 .summary(get(item, 'help.summary', desc));
34 each(get(item, 'help.option', []), obj => {
35 const [start, ...rest] = obj;
36 subCommand.option(start, ...rest);
37 });
38 each(get(item, 'subCommands', {}), (obj, cmd) => {
39 const desc = get(obj, 'help.description');
40 subCommand
41 .command(cmd)
42 .description(desc)
43 .summary(get(obj, 'help.summary', desc));
44 });
45 });
46 componentCommand.help();
47 }
48 async showRaw2() {
49 const [componentName, command] = this.raw;
50 const componentCommand = this.program.command(componentName).command(command).allowUnknownOption();
51 const instance = await loadComponent(componentName, { logger: this.logger.loggerInstance.__generate(componentName) });
52 const data = get(instance, `commands.${command}`);
53 if (isEmpty(data)) {
54 throw new utils.DevsError(`The command ${command} does not exist in the component ${componentName}`);
55 }
56 const desc = get(data, 'help.description');
57 const subCommand = componentCommand.description(desc).summary(get(data, 'help.summary', desc));
58 each(get(data, 'help.option', []), obj => {
59 const [start, ...rest] = obj;
60 subCommand.option(start, ...rest);
61 });
62 each(get(data, 'subCommands', {}), (obj, cmd) => {
63 const desc = get(obj, 'help.description');
64 const childCommand = subCommand

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected