Skip to content

Commit 17a31e3

Browse files
authored
Merge pull request atom#25442 from claytonrcarter/fix-usage-message
Fix usage message (closes atom#25441)
2 parents ae14722 + 19b28ed commit 17a31e3

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/main-process/main.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ const CSON = require('season');
1212
const yargs = require('yargs');
1313
const { app } = require('electron');
1414

15-
const version = `Atom : ${app.getVersion()}
16-
Electron: ${process.versions.electron}
17-
Chrome : ${process.versions.chrome}
18-
Node : ${process.versions.node}`;
19-
2015
const args = yargs(process.argv)
21-
.alias('v', 'version')
22-
.version(version)
16+
// Don't handle --help or --version here; they will be handled later.
17+
.help(false)
18+
.version(false)
2319
.alias('d', 'dev')
2420
.alias('t', 'test')
2521
.alias('r', 'resource-path').argv;

src/main-process/parse-command-line.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ module.exports = function parseCommandLine(processArgs) {
5757
.alias('f', 'foreground')
5858
.boolean('f')
5959
.describe('f', 'Keep the main process in the foreground.');
60-
options
61-
.alias('h', 'help')
62-
.boolean('h')
63-
.describe('h', 'Print this usage message.');
60+
options.help('help', 'Print this usage message.').alias('h', 'help');
6461
options
6562
.alias('l', 'log-file')
6663
.string('l')
@@ -136,7 +133,16 @@ module.exports = function parseCommandLine(processArgs) {
136133
'Enable low-level logging messages from Electron.'
137134
);
138135
options.boolean('uri-handler');
136+
options
137+
.version(
138+
dedent`Atom : ${version}
139+
Electron: ${process.versions.electron}
140+
Chrome : ${process.versions.chrome}
141+
Node : ${process.versions.node}`
142+
)
143+
.alias('v', 'version');
139144

145+
// NB: if --help or --version are given, this also displays the relevant message and exits
140146
let args = options.argv;
141147

142148
// If --uri-handler is set, then we parse NOTHING else
@@ -148,11 +154,6 @@ module.exports = function parseCommandLine(processArgs) {
148154
};
149155
}
150156

151-
if (args.help) {
152-
process.stdout.write(options.help());
153-
process.exit(0);
154-
}
155-
156157
const addToLastWindow = args['add'];
157158
const safeMode = args['safe'];
158159
const benchmark = args['benchmark'];

src/main-process/start.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ module.exports = function start(resourcePath, devResourcePath, startTime) {
3737
}
3838
});
3939

40-
const previousConsoleLog = console.log;
41-
console.log = nslog;
42-
4340
// TodoElectronIssue this should be set to true before Electron 12 - https://github.com/electron/electron/issues/18397
4441
app.allowRendererProcessReuse = false;
4542

4643
app.commandLine.appendSwitch('enable-experimental-web-platform-features');
4744

4845
const args = parseCommandLine(process.argv.slice(1));
46+
47+
// This must happen after parseCommandLine() because yargs uses console.log
48+
// to display the usage message.
49+
const previousConsoleLog = console.log;
50+
console.log = nslog;
51+
4952
args.resourcePath = normalizeDriveLetterName(resourcePath);
5053
args.devResourcePath = normalizeDriveLetterName(devResourcePath);
5154

0 commit comments

Comments
 (0)