From ee7754be4713e27d30f3033c43f7b8c87c475aea Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 23 Feb 2016 10:08:30 -0500 Subject: [PATCH] repl: accept no arguments to start() Currently, there is a check to ensure that the user either provides an object or a string to repl.start(). The string case is used to set a REPL prompt. However, a default of '> ' already exists, so forcing the user to specify a prompt is a bit redundant. This commit removes this restriction. Fixes: https://github.com/nodejs/node/issues/5385 PR-URL: https://github.com/nodejs/node/pull/5388 Reviewed-By: Ben Noordhuis Reviewed-By: Jeremiah Senkpiel Reviewed-By: Julian Duque --- doc/api/repl.markdown | 2 +- lib/repl.js | 2 -- test/parallel/test-repl-options.js | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/api/repl.markdown b/doc/api/repl.markdown index 2b61e5da38e1f9..e9bf877e8ac06c 100644 --- a/doc/api/repl.markdown +++ b/doc/api/repl.markdown @@ -243,7 +243,7 @@ blocks. The `preserveCursor` argument is passed to [`readline.prompt`][]. This i used primarily with `defineCommand`. It's also used internally to render each prompt line. -## repl.start(options) +## repl.start([options]) Returns and starts a `REPLServer` instance, that inherits from [Readline Interface][]. Accepts an "options" Object that takes diff --git a/lib/repl.js b/lib/repl.js index cc6191661f909f..7f913c0801738e 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -194,8 +194,6 @@ function REPLServer(prompt, prompt = options.prompt; dom = options.domain; replMode = options.replMode; - } else if (typeof prompt !== 'string') { - throw new Error('An options Object, or a prompt String are required'); } else { options = {}; } diff --git a/test/parallel/test-repl-options.js b/test/parallel/test-repl-options.js index 395cd3e3675635..70244802dd0f45 100644 --- a/test/parallel/test-repl-options.js +++ b/test/parallel/test-repl-options.js @@ -77,3 +77,17 @@ var r3 = repl.start({ assert.equal(r3.replMode, repl.REPL_MODE_MAGIC); assert.equal(r3.historySize, 50); + +// Verify that defaults are used when no arguments are provided +const r4 = repl.start(); + +assert.strictEqual(r4._prompt, '> '); +assert.strictEqual(r4.input, process.stdin); +assert.strictEqual(r4.output, process.stdout); +assert.strictEqual(r4.terminal, !!r4.output.isTTY); +assert.strictEqual(r4.useColors, r4.terminal); +assert.strictEqual(r4.useGlobal, false); +assert.strictEqual(r4.ignoreUndefined, false); +assert.strictEqual(r4.replMode, repl.REPL_MODE_SLOPPY); +assert.strictEqual(r4.historySize, 30); +r4.close();