bootstrap: print --help message using console.log

PR-URL: https://github.com/nodejs/node/pull/51463
Fixes: https://github.com/nodejs/node/issues/51448
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Jacob Hummer authored and GitHub committed 2024-05-12 21:43:13 +02:00
1 parent 11c90c15fb
commit c7d53f0169
2 files changed
+19 -6

No files matched your search

+7 -5
View File
@@ -202,6 +202,7 @@ function format(
function print(stream) {
const { options, aliases } = getCLIOptionsInfo();
const console = require('internal/console/global');
// Use 75 % of the available width, and at least 70 characters.
const width = MathMax(70, (stream.columns || 0) * 0.75);
@@ -212,21 +213,22 @@ function print(stream) {
'(default if no file name is provided, ' +
'interactive mode if a tty)' });
options.set('--', { helpText: 'indicate the end of node options' });
stream.write(
let helpText = (
'Usage: node [options] [ script.js ] [arguments]\n' +
' node inspect [options] [ script.js | host:port ] [arguments]\n\n' +
'Options:\n');
stream.write(indent(format({
helpText += (indent(format({
options, aliases, firstColumn, secondColumn,
}), 2));
stream.write('\nEnvironment variables:\n');
helpText += ('\nEnvironment variables:\n');
stream.write(format({
helpText += (format({
options: envVars, firstColumn, secondColumn,
}));
stream.write('\nDocumentation can be found at https://nodejs.org/\n');
helpText += ('\nDocumentation can be found at https://nodejs.org/');
console.log(helpText);
}
prepareMainThreadExecution();
+12 -1
View File
@@ -7,7 +7,8 @@ const common = require('../common');
// returns the proper set of cli options when invoked
const assert = require('assert');
const { exec } = require('child_process');
const { exec, spawn } = require('child_process');
const { once } = require('events');
let stdOut;
@@ -53,3 +54,13 @@ function testForSubstring(options) {
}
startPrintHelpTest();
// Test closed stdout for `node --help`. Like `node --help | head -n5`.
(async () => {
const cp = spawn(process.execPath, ['--help'], {
stdio: ['inherit', 'pipe', 'inherit'],
});
cp.stdout.destroy();
const [exitCode] = await once(cp, 'exit');
assert.strictEqual(exitCode, 0);
})().then(common.mustCall());