From 8afdabdd53806001ad62506def1d252d0502bc39 Mon Sep 17 00:00:00 2001 From: Koen Vlaswinkel Date: Mon, 20 Feb 2023 16:37:48 +0100 Subject: [PATCH] Use an options object for `runJsonCodeQlCliCommand` --- extensions/ql-vscode/src/cli.ts | 73 +++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/extensions/ql-vscode/src/cli.ts b/extensions/ql-vscode/src/cli.ts index 7145d042e..7e978407f 100644 --- a/extensions/ql-vscode/src/cli.ts +++ b/extensions/ql-vscode/src/cli.ts @@ -564,9 +564,15 @@ export class CodeQLCliServer implements Disposable { command: string[], commandArgs: string[], description: string, - addFormat = true, - progressReporter?: ProgressReporter, - onLine?: OnLineCallback, + { + addFormat = true, + progressReporter, + onLine, + }: { + addFormat?: boolean; + progressReporter?: ProgressReporter; + onLine?: OnLineCallback; + } = {}, ): Promise { let args: string[] = []; if (addFormat) @@ -617,8 +623,13 @@ export class CodeQLCliServer implements Disposable { command: string[], commandArgs: string[], description: string, - addFormat = true, - progressReporter?: ProgressReporter, + { + addFormat, + progressReporter, + }: { + addFormat?: boolean; + progressReporter?: ProgressReporter; + } = {}, ): Promise { const accessToken = await this.app.credentials.getExistingAccessToken(); @@ -628,24 +639,26 @@ export class CodeQLCliServer implements Disposable { command, [...extraArgs, ...commandArgs], description, - addFormat, - progressReporter, - async (line) => { - if (line.startsWith("Enter value for --github-auth-stdin")) { - try { - return await this.app.credentials.getAccessToken(); - } catch (e) { - // If the user cancels the authentication prompt, we still need to give a value to the CLI. - // By giving a potentially invalid value, the user will just get a 401/403 when they try to access a - // private package and the access token is invalid. - // This code path is very rare to hit. It would only be hit if the user is logged in when - // starting the command, then logging out before the getAccessToken() is called again and - // then cancelling the authentication prompt. - return accessToken; + { + addFormat, + progressReporter, + onLine: async (line) => { + if (line.startsWith("Enter value for --github-auth-stdin")) { + try { + return await this.app.credentials.getAccessToken(); + } catch (e) { + // If the user cancels the authentication prompt, we still need to give a value to the CLI. + // By giving a potentially invalid value, the user will just get a 401/403 when they try to access a + // private package and the access token is invalid. + // This code path is very rare to hit. It would only be hit if the user is logged in when + // starting the command, then logging out before the getAccessToken() is called again and + // then cancelling the authentication prompt. + return accessToken; + } } - } - return undefined; + return undefined; + }, }, ); } @@ -714,7 +727,9 @@ export class CodeQLCliServer implements Disposable { ["resolve", "qlref"], subcommandArgs, "Resolving qlref", - false, + { + addFormat: false, + }, ); } @@ -787,7 +802,9 @@ export class CodeQLCliServer implements Disposable { ["resolve", "ml-models"], args, "Resolving ML models", - false, + { + addFormat: false, + }, ); } @@ -811,8 +828,9 @@ export class CodeQLCliServer implements Disposable { ["resolve", "ram"], args, "Resolving RAM settings", - true, - progressReporter, + { + progressReporter, + }, ); } /** @@ -1227,12 +1245,13 @@ export class CodeQLCliServer implements Disposable { async packAdd(dir: string, queryLanguage: QueryLanguage) { const args = ["--dir", dir]; args.push(`codeql/${queryLanguage}-all`); - const addFormat = false; return this.runJsonCodeQlCliCommandWithAuthentication( ["pack", "add"], args, `Adding and installing ${queryLanguage} pack dependency.`, - addFormat, + { + addFormat: false, + }, ); }