Skip to content

Commit ee7754b

Browse files
committed
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: #5385 PR-URL: #5388 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Julian Duque <julianduquej@gmail.com>
1 parent 54cbf28 commit ee7754b

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎doc/api/repl.markdown‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ blocks. The `preserveCursor` argument is passed to [`readline.prompt`][]. This i
243243
used primarily with `defineCommand`. It's also used internally to render each
244244
prompt line.
245245

246-
## repl.start(options)
246+
## repl.start([options])
247247

248248
Returns and starts a `REPLServer` instance, that inherits from
249249
[Readline Interface][]. Accepts an "options" Object that takes

‎lib/repl.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ function REPLServer(prompt,
194194
prompt=options.prompt;
195195
dom=options.domain;
196196
replMode=options.replMode;
197-
}elseif(typeofprompt!=='string'){
198-
thrownewError('An options Object, or a prompt String are required');
199197
}else{
200198
options={};
201199
}

‎test/parallel/test-repl-options.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,17 @@ var r3 = repl.start({
7777

7878
assert.equal(r3.replMode,repl.REPL_MODE_MAGIC);
7979
assert.equal(r3.historySize,50);
80+
81+
// Verify that defaults are used when no arguments are provided
82+
constr4=repl.start();
83+
84+
assert.strictEqual(r4._prompt,'> ');
85+
assert.strictEqual(r4.input,process.stdin);
86+
assert.strictEqual(r4.output,process.stdout);
87+
assert.strictEqual(r4.terminal,!!r4.output.isTTY);
88+
assert.strictEqual(r4.useColors,r4.terminal);
89+
assert.strictEqual(r4.useGlobal,false);
90+
assert.strictEqual(r4.ignoreUndefined,false);
91+
assert.strictEqual(r4.replMode,repl.REPL_MODE_SLOPPY);
92+
assert.strictEqual(r4.historySize,30);
93+
r4.close();

0 commit comments

Comments
 (0)