Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a52de8c

Browse filesBrowse files
jcbhmrmarco-ippolito
authored andcommitted
bootstrap: print --help message using console.log
PR-URL: #51463 Fixes: #51448 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent a6dd864 commit a52de8c
Copy full SHA for a52de8c

2 files changed

+19-6Lines changed: 19 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/main/print_help.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/print_help.js
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ function format(
202202

203203
function print(stream) {
204204
const { options, aliases } = getCLIOptionsInfo();
205+
const console = require('internal/console/global');
205206

206207
// Use 75 % of the available width, and at least 70 characters.
207208
const width = MathMax(70, (stream.columns || 0) * 0.75);
@@ -212,21 +213,22 @@ function print(stream) {
212213
'(default if no file name is provided, ' +
213214
'interactive mode if a tty)' });
214215
options.set('--', { helpText: 'indicate the end of node options' });
215-
stream.write(
216+
let helpText = (
216217
'Usage: node [options] [ script.js ] [arguments]\n' +
217218
' node inspect [options] [ script.js | host:port ] [arguments]\n\n' +
218219
'Options:\n');
219-
stream.write(indent(format({
220+
helpText += (indent(format({
220221
options, aliases, firstColumn, secondColumn,
221222
}), 2));
222223

223-
stream.write('\nEnvironment variables:\n');
224+
helpText += ('\nEnvironment variables:\n');
224225

225-
stream.write(format({
226+
helpText += (format({
226227
options: envVars, firstColumn, secondColumn,
227228
}));
228229

229-
stream.write('\nDocumentation can be found at https://nodejs.org/\n');
230+
helpText += ('\nDocumentation can be found at https://nodejs.org/');
231+
console.log(helpText);
230232
}
231233

232234
prepareMainThreadExecution();
Collapse file

‎test/parallel/test-cli-node-print-help.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cli-node-print-help.js
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const common = require('../common');
77
// returns the proper set of cli options when invoked
88

99
const assert = require('assert');
10-
const { exec } = require('child_process');
10+
const { exec, spawn } = require('child_process');
11+
const { once } = require('events');
1112
let stdOut;
1213

1314

@@ -53,3 +54,13 @@ function testForSubstring(options) {
5354
}
5455

5556
startPrintHelpTest();
57+
58+
// Test closed stdout for `node --help`. Like `node --help | head -n5`.
59+
(async () => {
60+
const cp = spawn(process.execPath, ['--help'], {
61+
stdio: ['inherit', 'pipe', 'inherit'],
62+
});
63+
cp.stdout.destroy();
64+
const [exitCode] = await once(cp, 'exit');
65+
assert.strictEqual(exitCode, 0);
66+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.