Skip to content

doc/bug: repl.start() prompt doesn't default to '> ' #5385

@greg-js

Description

@greg-js

Following the contents of ./doc/api/repl.markdown, lines 217-227, I put this in repl_test.js:

const repl = require('repl');

var replServer = repl.start();
replServer.defineCommand('sayhello', {
  help: 'Say hello',
  action: function(name) {
    this.write(`Hello, ${name}!\n`);
    this.displayPrompt();
  }
});

Running that, I get

repl.js:198
    throw new Error('An options Object, or a prompt String are required');

On line 252 of ./doc/api/repl.markdown, it is noted that prompt should default to > if an options object is passed in, but not what should happen if it is called without arguments.

I took a look at ./lib/readline.js and ./lib/repl.js and the culprit for the code snippet failing (if the docs represent the intended functionality) is line 197-198 of ./lib/repl.js.

Either way, it seems to me that either the docs should be updated to reflect the code, or those lines in ./lib/repl.js should be removed to make it fall back to an empty object and thus the default > prompt. No PR submitted because I don't know which of the directions to go in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions