chore: remove duplication in parameter definitions (#9805)

This commit is contained in:
Alex Rudenko 2023-03-08 13:36:31 +01:00 committed by GitHub
parent c1a7c736ff
commit 89bdfb5206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,33 +50,45 @@ export class CLI {
this.#cachePath = cachePath;
}
#defineBrowserParameter(yargs: yargs.Argv<unknown>): void {
yargs.positional('browser', {
description: 'The browser version',
type: 'string',
coerce: (opt): InstallArgs['browser'] => {
return {
name: this.#parseBrowser(opt),
buildId: this.#parseBuildId(opt),
};
},
});
}
#definePlatformParameter(yargs: yargs.Argv<unknown>): void {
yargs.option('platform', {
type: 'string',
desc: 'Platform that the binary needs to be compatible with.',
choices: Object.values(BrowserPlatform),
defaultDescription: 'Auto-detected by default.',
});
}
#definePathParameter(yargs: yargs.Argv<unknown>): void {
yargs.option('path', {
type: 'string',
desc: 'Path to the root folder for the browser downloads and installation',
default: process.cwd(),
});
}
async run(argv: string[]): Promise<void> {
await yargs(hideBin(argv))
.command(
'install <browser>',
'Download and install the specified browser',
yargs => {
yargs.positional('browser', {
description: 'The browser version',
type: 'string',
coerce: (opt): InstallArgs['browser'] => {
return {
name: this.#parseBrowser(opt),
buildId: this.#parseBuildId(opt),
};
},
});
yargs.option('platform', {
type: 'string',
desc: 'Platform that the binary needs to be compatible with.',
choices: Object.values(BrowserPlatform),
defaultDescription: 'Auto-detected by default.',
});
yargs.option('path', {
type: 'string',
desc: 'Path where the browsers will be downloaded to and installed from',
default: process.cwd(),
});
this.#defineBrowserParameter(yargs);
this.#definePlatformParameter(yargs);
this.#definePathParameter(yargs);
},
async argv => {
const args = argv as unknown as InstallArgs;
@ -115,32 +127,14 @@ export class CLI {
'launch <browser>',
'Launch the specified browser',
yargs => {
yargs.positional('browser', {
description: 'The browser version',
type: 'string',
coerce: (opt): LaunchArgs['browser'] => {
return {
name: this.#parseBrowser(opt),
buildId: this.#parseBuildId(opt),
};
},
});
this.#defineBrowserParameter(yargs);
this.#definePlatformParameter(yargs);
this.#definePathParameter(yargs);
yargs.option('detached', {
type: 'boolean',
desc: 'Whether to detach the child process.',
default: false,
});
yargs.option('platform', {
type: 'string',
desc: 'Platform that the binary needs to be compatible with.',
choices: Object.values(BrowserPlatform),
defaultDescription: 'Auto-detected by default.',
});
yargs.option('path', {
type: 'string',
desc: 'Path where the browsers will be downloaded to and installed from',
default: process.cwd(),
});
},
async argv => {
const args = argv as unknown as LaunchArgs;