Skip to content

Commit 95caf0a

Browse files
committed
added extra features to repl.js
added more detailed help messages and added a 'helpC' command
1 parent 8d7201f commit 95caf0a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/repl.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,12 +1781,23 @@ function defineDefaultCommands(repl) {
17811781
const line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`;
17821782
this.output.write(line);
17831783
});
1784+
this.output.write('\n in the Node.js REPL you may write regular JavaScript code\nand use REPL commands, the REPL commands are listed above\n')
17841785
this.output.write('\nPress Ctrl+C to abort current expression, ' +
17851786
'Ctrl+D to exit the REPL\n');
17861787
this.displayPrompt();
17871788
},
17881789
});
1789-
1790+
repl.defineCommand('helpC', {
1791+
help: 'get help for a specific command',
1792+
action: function(cmd) {
1793+
if(this.commands[cmd]) {
1794+
this.output.write(cmd.help);
1795+
} else {
1796+
this.output.write('Command not found');
1797+
}
1798+
this.displayPrompt();
1799+
}
1800+
})
17901801
repl.defineCommand('save', {
17911802
help: 'Save all evaluated commands in this REPL session to a file',
17921803
action: function(file) {
@@ -1801,7 +1812,7 @@ function defineDefaultCommands(repl) {
18011812
});
18021813

18031814
repl.defineCommand('load', {
1804-
help: 'Load JS from a file into the REPL session',
1815+
help: 'Load JS (variables, functions, etc) from a file into the REPL session',
18051816
action: function(file) {
18061817
try {
18071818
const stats = fs.statSync(file);
@@ -1826,7 +1837,7 @@ function defineDefaultCommands(repl) {
18261837
});
18271838
if (repl.terminal) {
18281839
repl.defineCommand('editor', {
1829-
help: 'Enter editor mode',
1840+
help: 'Enter editor mode (JS)',
18301841
action() {
18311842
_turnOnEditorMode(this);
18321843
this.output.write(

0 commit comments

Comments
 (0)