From 0ae715d23914325957e2150c380f372a266bb02b Mon Sep 17 00:00:00 2001 From: Clayton Carter Date: Wed, 4 May 2022 19:37:45 -0400 Subject: [PATCH 1/3] fix: Don't swallow console.log messages until after CLI arguments are parsed yargs depends on an intact console.log to display help and usage messages, so just delay the override by a few statements. --- src/main-process/start.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main-process/start.js b/src/main-process/start.js index 5ba697a88..122c332f6 100644 --- a/src/main-process/start.js +++ b/src/main-process/start.js @@ -37,15 +37,18 @@ module.exports = function start(resourcePath, devResourcePath, startTime) { } }); - const previousConsoleLog = console.log; - console.log = nslog; - // TodoElectronIssue this should be set to true before Electron 12 - https://github.com/electron/electron/issues/18397 app.allowRendererProcessReuse = false; app.commandLine.appendSwitch('enable-experimental-web-platform-features'); const args = parseCommandLine(process.argv.slice(1)); + + // This must happen after parseCommandLine() because yargs uses console.log + // to display the usage message. + const previousConsoleLog = console.log; + console.log = nslog; + args.resourcePath = normalizeDriveLetterName(resourcePath); args.devResourcePath = normalizeDriveLetterName(devResourcePath); From 98ab593f463816e73ba880606fa3e715587a609b Mon Sep 17 00:00:00 2001 From: Clayton Carter Date: Wed, 4 May 2022 22:26:49 -0400 Subject: [PATCH 2/3] fix: Prevent the first call to yargs from responding to `--help` The second call to yargs should be responsible for printing the main usage message. This also fixes the `--help` description w/i the usage message, which was only using the yargs default description. --- src/main-process/main.js | 1 + src/main-process/parse-command-line.js | 10 +--------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main-process/main.js b/src/main-process/main.js index 4ccd361bd..cf7fcf523 100644 --- a/src/main-process/main.js +++ b/src/main-process/main.js @@ -20,6 +20,7 @@ Node : ${process.versions.node}`; const args = yargs(process.argv) .alias('v', 'version') .version(version) + .help(false) .alias('d', 'dev') .alias('t', 'test') .alias('r', 'resource-path').argv; diff --git a/src/main-process/parse-command-line.js b/src/main-process/parse-command-line.js index 61614e04a..142110e4b 100644 --- a/src/main-process/parse-command-line.js +++ b/src/main-process/parse-command-line.js @@ -57,10 +57,7 @@ module.exports = function parseCommandLine(processArgs) { .alias('f', 'foreground') .boolean('f') .describe('f', 'Keep the main process in the foreground.'); - options - .alias('h', 'help') - .boolean('h') - .describe('h', 'Print this usage message.'); + options.help('help', 'Print this usage message.').alias('h', 'help'); options .alias('l', 'log-file') .string('l') @@ -148,11 +145,6 @@ module.exports = function parseCommandLine(processArgs) { }; } - if (args.help) { - process.stdout.write(options.help()); - process.exit(0); - } - const addToLastWindow = args['add']; const safeMode = args['safe']; const benchmark = args['benchmark']; From 19b28ed492bf81a51fe92295cdadaf267114864b Mon Sep 17 00:00:00 2001 From: Clayton Carter Date: Wed, 4 May 2022 22:26:06 -0400 Subject: [PATCH 3/3] fix: Include `-v`/`--version` in the main usage message --- src/main-process/main.js | 9 ++------- src/main-process/parse-command-line.js | 9 +++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main-process/main.js b/src/main-process/main.js index cf7fcf523..28b6f3f26 100644 --- a/src/main-process/main.js +++ b/src/main-process/main.js @@ -12,15 +12,10 @@ const CSON = require('season'); const yargs = require('yargs'); const { app } = require('electron'); -const version = `Atom : ${app.getVersion()} -Electron: ${process.versions.electron} -Chrome : ${process.versions.chrome} -Node : ${process.versions.node}`; - const args = yargs(process.argv) - .alias('v', 'version') - .version(version) + // Don't handle --help or --version here; they will be handled later. .help(false) + .version(false) .alias('d', 'dev') .alias('t', 'test') .alias('r', 'resource-path').argv; diff --git a/src/main-process/parse-command-line.js b/src/main-process/parse-command-line.js index 142110e4b..e152ee7e8 100644 --- a/src/main-process/parse-command-line.js +++ b/src/main-process/parse-command-line.js @@ -133,7 +133,16 @@ module.exports = function parseCommandLine(processArgs) { 'Enable low-level logging messages from Electron.' ); options.boolean('uri-handler'); + options + .version( + dedent`Atom : ${version} + Electron: ${process.versions.electron} + Chrome : ${process.versions.chrome} + Node : ${process.versions.node}` + ) + .alias('v', 'version'); + // NB: if --help or --version are given, this also displays the relevant message and exits let args = options.argv; // If --uri-handler is set, then we parse NOTHING else