From f3723cbdbdfbce740697f0aa4260cb1cf93248d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Fri, 24 May 2024 10:51:59 +0200 Subject: [PATCH] Delegate showing help to the back end process. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #13727 The approach is to add non-functional cli contributions for any arguments that concern only the electron-main process. Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder --- packages/core/package.json | 3 ++ .../electron-main-application.ts | 1 + .../cli/electron-backend-cli-module.ts | 24 +++++++++++++ .../cli/electron-cli-contribution.ts | 35 +++++++++++++++++++ packages/core/src/node/cli.ts | 4 +-- 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 packages/core/src/electron-node/cli/electron-backend-cli-module.ts create mode 100644 packages/core/src/electron-node/cli/electron-cli-contribution.ts diff --git a/packages/core/package.json b/packages/core/package.json index f127f61e37f06..d96b484289b33 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -152,6 +152,9 @@ "frontend": "lib/browser/window/browser-window-module", "frontendElectron": "lib/electron-browser/window/electron-window-module" }, + { + "backendElectron": "lib/electron-node/cli/electron-backend-cli-module" + }, { "frontend": "lib/browser/keyboard/browser-keyboard-module", "frontendElectron": "lib/electron-browser/keyboard/electron-keyboard-module", diff --git a/packages/core/src/electron-main/electron-main-application.ts b/packages/core/src/electron-main/electron-main-application.ts index e6fac94c46733..8d59807252593 100644 --- a/packages/core/src/electron-main/electron-main-application.ts +++ b/packages/core/src/electron-main/electron-main-application.ts @@ -209,6 +209,7 @@ export class ElectronMainApplication { async start(config: FrontendApplicationConfig): Promise { const argv = this.processArgv.getProcessArgvWithoutBin(process.argv); createYargs(argv, process.cwd()) + .help(false) .command('$0 [file]', false, cmd => cmd .option('electronUserData', { diff --git a/packages/core/src/electron-node/cli/electron-backend-cli-module.ts b/packages/core/src/electron-node/cli/electron-backend-cli-module.ts new file mode 100644 index 0000000000000..2b7a98176cb9f --- /dev/null +++ b/packages/core/src/electron-node/cli/electron-backend-cli-module.ts @@ -0,0 +1,24 @@ +// ***************************************************************************** +// Copyright (C) 2024 STMicroelectronics and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0. +// +// This Source Code may also be made available under the following Secondary +// Licenses when the conditions for such availability set forth in the Eclipse +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 +// with the GNU Classpath Exception which is available at +// https://www.gnu.org/software/classpath/license.html. +// +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 +// ***************************************************************************** + +import { ContainerModule } from 'inversify'; +import { ElectronCliContribution } from './electron-cli-contribution'; +import { CliContribution } from '../../node'; + +export default new ContainerModule(bind => { + bind(ElectronCliContribution).toSelf().inSingletonScope(); + bind(CliContribution).toService(ElectronCliContribution); +}); diff --git a/packages/core/src/electron-node/cli/electron-cli-contribution.ts b/packages/core/src/electron-node/cli/electron-cli-contribution.ts new file mode 100644 index 0000000000000..c8b5be382679a --- /dev/null +++ b/packages/core/src/electron-node/cli/electron-cli-contribution.ts @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (C) 2024 STMicroelectronics and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { injectable } from 'inversify'; +import { Argv, Arguments } from 'yargs'; +import { CliContribution } from '../../node'; +import { MaybePromise } from '../../common'; + +@injectable() +export class ElectronCliContribution implements CliContribution { + + configure(conf: Argv): void { + conf.option('electronUserData', { + type: 'string', + describe: 'The area where the electron main process puts its data' + }); + } + + setArguments(args: Arguments): MaybePromise { + } + +} diff --git a/packages/core/src/node/cli.ts b/packages/core/src/node/cli.ts index 949d233dfaf2f..28b9e7f0c8aa7 100644 --- a/packages/core/src/node/cli.ts +++ b/packages/core/src/node/cli.ts @@ -38,7 +38,7 @@ export class CliManager { async initializeCli(argv: string[], postSetArguments: () => Promise, defaultCommand: () => Promise): Promise { const pack = require('../../package.json'); const version = pack.version; - const command = yargs.version(version); + const command = yargs(argv, process.cwd()).version(version); command.exitProcess(this.isExit()); for (const contrib of this.contributionsProvider.getContributions()) { contrib.configure(command); @@ -54,7 +54,7 @@ export class CliManager { await postSetArguments(); }) .command('$0', false, () => { }, defaultCommand) - .parse(argv); + .parse(); } protected isExit(): boolean {