GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bootstrap: print `--help` message using `console.log` · nodejs/node@a52de8c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/main
    • print_help.js
  • test/parallel
    • test-cli-node-print-help.js
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.