1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
class CommandLineOption {
private flags: string[];
public constructor(
private description: string,
...flags: string[]
) {
this.flags = flags;
}
public get match(): boolean {
return this.flags.some((flag) => process.argv.includes(flag));
}
public format(): string {
return formatOption(this.description, ...this.flags);
}
}
class DevelopmentCommandLineOption extends CommandLineOption {
public constructor(...flags: string[]) {
super('', ...flags);
}
public get match(): boolean {
return process.env.NODE_ENV === 'development' && super.match;
}
}
export const CommandLineOptions = {
help: new CommandLineOption('Print this help text', '--help', '-h'),
version: new CommandLineOption('Print the app version', '--version'),
showChanges: new CommandLineOption('Show changes dialog', '--show-changes'),
disableResetNavigation: new DevelopmentCommandLineOption('--disable-reset-navigation'),
disableDevtoolsOpen: new DevelopmentCommandLineOption('--disable-devtools-open'),
forwardRendererLog: new DevelopmentCommandLineOption('--forward-renderer-log'),
} as const;
export function printCommandLineOptions() {
Object.values(CommandLineOptions).forEach((option) => {
if (!(option instanceof DevelopmentCommandLineOption)) {
console.log(option.format());
}
});
}
export function printElectronOptions() {
console.log(formatOption('Run without renderer process sandboxed', '--no-sandbox'));
console.log(formatOption('Run without hardware acceleration for graphics', '--disable-gpu'));
}
// This functions format options into one line, e.g.
// --help Print this help text
// The line starts with 4 spaces and the flags and description are separated with spaces to align
// the descriptions
function formatOption(description: string, ...flags: string[]) {
const joinedFlags = flags.join(', ');
const padding = ' ';
const paddedFlags = (joinedFlags + padding).slice(0, -joinedFlags.length);
return ' ' + paddedFlags + description;
}
|