Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commita52de8c

Browse files
jcbhmrmarco-ippolito
authored andcommitted
bootstrap: print--help message usingconsole.log
PR-URL:#51463Fixes:#51448Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parenta6dd864 commita52de8c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

‎lib/internal/main/print_help.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ function format(
202202

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

206207
// Use 75 % of the available width, and at least 70 characters.
207208
constwidth=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+
lethelpText=(
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();

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

Lines 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
constassert=require('assert');
10-
const{ exec}=require('child_process');
10+
const{ exec, spawn}=require('child_process');
11+
const{ once}=require('events');
1112
letstdOut;
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+
constcp=spawn(process.execPath,['--help'],{
61+
stdio:['inherit','pipe','inherit'],
62+
});
63+
cp.stdout.destroy();
64+
const[exitCode]=awaitonce(cp,'exit');
65+
assert.strictEqual(exitCode,0);
66+
})().then(common.mustCall());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp