From 9b99e15ff059e2ba90074af04b63f24e3b5c38bb Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Mon, 12 Feb 2018 17:50:02 -0800 Subject: [PATCH] Send usage text to stdout if --help specified Fixes #802. --- cli.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/cli.js b/cli.js index a6b761e4..ccb5ff5d 100755 --- a/cli.js +++ b/cli.js @@ -18,13 +18,24 @@ var usage = fs.readFileSync(path.join(__dirname, 'usage.txt')).toString() var args = common.parseCLIArgs(process.argv.slice(2)) -if (!args.dir) { - // temporary fix for https://github.com/nodejs/node/issues/6456 - if (process.stderr._handle && process.stderr._handle.setBlocking) { - process.stderr._handle.setBlocking(true) +// temporary fix for https://github.com/nodejs/node/issues/6456 +var stdioWriters = [process.stdout, process.stderr] +stdioWriters.forEach(function (stdioWriter) { + if (stdioWriter._handle && stdioWriter._handle.setBlocking) { + stdioWriter._handle.setBlocking(true) } - console.error(usage) - process.exit(1) +}) + +function printUsageAndExit (isError) { + var print = isError ? console.error : console.log + print(usage) + process.exit(isError ? 1 : 0) +} + +if (args.help) { + printUsageAndExit(false) +} else if (!args.dir) { + printUsageAndExit(true) } packager(args, function done (err, appPaths) {