| 18 | } |
| 19 | |
| 20 | export function defineDefaultCommandsOnRepl(replServer: REPLServer): void { |
| 21 | replServer.defineCommand('help', { |
| 22 | help: 'Show REPL options', |
| 23 | action(name?: string) { |
| 24 | this.clearBufferedCommand(); |
| 25 | |
| 26 | if (name) { |
| 27 | // Considering native commands before native nestjs injected functions. |
| 28 | const nativeCommandOrFunction = |
| 29 | this.commands[name] || this.context[name]; |
| 30 | // NOTE: If the command was retrieve from the context, it will have a `help` |
| 31 | // getter property that outputs the helper message and returns undefined. |
| 32 | // But if the command was retrieve from the `commands` object, it will |
| 33 | // have a `help` property that returns the helper message. |
| 34 | const helpMessage = nativeCommandOrFunction?.help; |
| 35 | if (helpMessage) { |
| 36 | this.output.write(`${helpMessage}\n`); |
| 37 | } |
| 38 | } else { |
| 39 | listAllCommands(this); |
| 40 | this.output.write('\n\n'); |
| 41 | this.context.help(); |
| 42 | this.output.write( |
| 43 | '\nPress Ctrl+C to abort current expression, Ctrl+D to exit the REPL\n', |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | this.displayPrompt(); |
| 48 | }, |
| 49 | }); |
| 50 | } |