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[],
commandArgs: string[],
description: string,
addFormat = true,
progressReporter?: ProgressReporter,
onLine?: OnLineCallback,
{
addFormat = true,
progressReporter,
onLine,
}: {
addFormat?: boolean;
progressReporter?: ProgressReporter;
onLine?: OnLineCallback;
} = {},
): Promise<OutputType> {
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<OutputType> {
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,
},
);
}