Use an options object for runJsonCodeQlCliCommand

This commit is contained in:
Koen Vlaswinkel
2023-02-20 16:37:48 +01:00
parent c6481ca6ff
commit 8afdabdd53

View File

@@ -564,9 +564,15 @@ export class CodeQLCliServer implements Disposable {
command: string[], command: string[],
commandArgs: string[], commandArgs: string[],
description: string, description: string,
addFormat = true, {
progressReporter?: ProgressReporter, addFormat = true,
onLine?: OnLineCallback, progressReporter,
onLine,
}: {
addFormat?: boolean;
progressReporter?: ProgressReporter;
onLine?: OnLineCallback;
} = {},
): Promise<OutputType> { ): Promise<OutputType> {
let args: string[] = []; let args: string[] = [];
if (addFormat) if (addFormat)
@@ -617,8 +623,13 @@ export class CodeQLCliServer implements Disposable {
command: string[], command: string[],
commandArgs: string[], commandArgs: string[],
description: string, description: string,
addFormat = true, {
progressReporter?: ProgressReporter, addFormat,
progressReporter,
}: {
addFormat?: boolean;
progressReporter?: ProgressReporter;
} = {},
): Promise<OutputType> { ): Promise<OutputType> {
const accessToken = await this.app.credentials.getExistingAccessToken(); const accessToken = await this.app.credentials.getExistingAccessToken();
@@ -628,24 +639,26 @@ export class CodeQLCliServer implements Disposable {
command, command,
[...extraArgs, ...commandArgs], [...extraArgs, ...commandArgs],
description, description,
addFormat, {
progressReporter, addFormat,
async (line) => { progressReporter,
if (line.startsWith("Enter value for --github-auth-stdin")) { onLine: async (line) => {
try { if (line.startsWith("Enter value for --github-auth-stdin")) {
return await this.app.credentials.getAccessToken(); try {
} catch (e) { return await this.app.credentials.getAccessToken();
// If the user cancels the authentication prompt, we still need to give a value to the CLI. } catch (e) {
// By giving a potentially invalid value, the user will just get a 401/403 when they try to access a // If the user cancels the authentication prompt, we still need to give a value to the CLI.
// private package and the access token is invalid. // By giving a potentially invalid value, the user will just get a 401/403 when they try to access a
// This code path is very rare to hit. It would only be hit if the user is logged in when // private package and the access token is invalid.
// starting the command, then logging out before the getAccessToken() is called again and // This code path is very rare to hit. It would only be hit if the user is logged in when
// then cancelling the authentication prompt. // starting the command, then logging out before the getAccessToken() is called again and
return accessToken; // then cancelling the authentication prompt.
return accessToken;
}
} }
}
return undefined; return undefined;
},
}, },
); );
} }
@@ -714,7 +727,9 @@ export class CodeQLCliServer implements Disposable {
["resolve", "qlref"], ["resolve", "qlref"],
subcommandArgs, subcommandArgs,
"Resolving qlref", "Resolving qlref",
false, {
addFormat: false,
},
); );
} }
@@ -787,7 +802,9 @@ export class CodeQLCliServer implements Disposable {
["resolve", "ml-models"], ["resolve", "ml-models"],
args, args,
"Resolving ML models", "Resolving ML models",
false, {
addFormat: false,
},
); );
} }
@@ -811,8 +828,9 @@ export class CodeQLCliServer implements Disposable {
["resolve", "ram"], ["resolve", "ram"],
args, args,
"Resolving RAM settings", "Resolving RAM settings",
true, {
progressReporter, progressReporter,
},
); );
} }
/** /**
@@ -1227,12 +1245,13 @@ export class CodeQLCliServer implements Disposable {
async packAdd(dir: string, queryLanguage: QueryLanguage) { async packAdd(dir: string, queryLanguage: QueryLanguage) {
const args = ["--dir", dir]; const args = ["--dir", dir];
args.push(`codeql/${queryLanguage}-all`); args.push(`codeql/${queryLanguage}-all`);
const addFormat = false;
return this.runJsonCodeQlCliCommandWithAuthentication( return this.runJsonCodeQlCliCommandWithAuthentication(
["pack", "add"], ["pack", "add"],
args, args,
`Adding and installing ${queryLanguage} pack dependency.`, `Adding and installing ${queryLanguage} pack dependency.`,
addFormat, {
addFormat: false,
},
); );
} }