Skip to content

Commit 8afdabd

Browse files
committed
Use an options object for runJsonCodeQlCliCommand
1 parent c6481ca commit 8afdabd

File tree

1 file changed

+46
-27
lines changed
  • extensions/ql-vscode/src

1 file changed

+46
-27
lines changed

extensions/ql-vscode/src/cli.ts

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,15 @@ export class CodeQLCliServer implements Disposable {
564564
command: string[],
565565
commandArgs: string[],
566566
description: string,
567-
addFormat = true,
568-
progressReporter?: ProgressReporter,
569-
onLine?: OnLineCallback,
567+
{
568+
addFormat = true,
569+
progressReporter,
570+
onLine,
571+
}: {
572+
addFormat?: boolean;
573+
progressReporter?: ProgressReporter;
574+
onLine?: OnLineCallback;
575+
} = {},
570576
): Promise<OutputType> {
571577
let args: string[] = [];
572578
if (addFormat)
@@ -617,8 +623,13 @@ export class CodeQLCliServer implements Disposable {
617623
command: string[],
618624
commandArgs: string[],
619625
description: string,
620-
addFormat = true,
621-
progressReporter?: ProgressReporter,
626+
{
627+
addFormat,
628+
progressReporter,
629+
}: {
630+
addFormat?: boolean;
631+
progressReporter?: ProgressReporter;
632+
} = {},
622633
): Promise<OutputType> {
623634
const accessToken = await this.app.credentials.getExistingAccessToken();
624635

@@ -628,24 +639,26 @@ export class CodeQLCliServer implements Disposable {
628639
command,
629640
[...extraArgs, ...commandArgs],
630641
description,
631-
addFormat,
632-
progressReporter,
633-
async (line) => {
634-
if (line.startsWith("Enter value for --github-auth-stdin")) {
635-
try {
636-
return await this.app.credentials.getAccessToken();
637-
} catch (e) {
638-
// If the user cancels the authentication prompt, we still need to give a value to the CLI.
639-
// By giving a potentially invalid value, the user will just get a 401/403 when they try to access a
640-
// private package and the access token is invalid.
641-
// This code path is very rare to hit. It would only be hit if the user is logged in when
642-
// starting the command, then logging out before the getAccessToken() is called again and
643-
// then cancelling the authentication prompt.
644-
return accessToken;
642+
{
643+
addFormat,
644+
progressReporter,
645+
onLine: async (line) => {
646+
if (line.startsWith("Enter value for --github-auth-stdin")) {
647+
try {
648+
return await this.app.credentials.getAccessToken();
649+
} catch (e) {
650+
// If the user cancels the authentication prompt, we still need to give a value to the CLI.
651+
// By giving a potentially invalid value, the user will just get a 401/403 when they try to access a
652+
// private package and the access token is invalid.
653+
// This code path is very rare to hit. It would only be hit if the user is logged in when
654+
// starting the command, then logging out before the getAccessToken() is called again and
655+
// then cancelling the authentication prompt.
656+
return accessToken;
657+
}
645658
}
646-
}
647659

648-
return undefined;
660+
return undefined;
661+
},
649662
},
650663
);
651664
}
@@ -714,7 +727,9 @@ export class CodeQLCliServer implements Disposable {
714727
["resolve", "qlref"],
715728
subcommandArgs,
716729
"Resolving qlref",
717-
false,
730+
{
731+
addFormat: false,
732+
},
718733
);
719734
}
720735

@@ -787,7 +802,9 @@ export class CodeQLCliServer implements Disposable {
787802
["resolve", "ml-models"],
788803
args,
789804
"Resolving ML models",
790-
false,
805+
{
806+
addFormat: false,
807+
},
791808
);
792809
}
793810

@@ -811,8 +828,9 @@ export class CodeQLCliServer implements Disposable {
811828
["resolve", "ram"],
812829
args,
813830
"Resolving RAM settings",
814-
true,
815-
progressReporter,
831+
{
832+
progressReporter,
833+
},
816834
);
817835
}
818836
/**
@@ -1227,12 +1245,13 @@ export class CodeQLCliServer implements Disposable {
12271245
async packAdd(dir: string, queryLanguage: QueryLanguage) {
12281246
const args = ["--dir", dir];
12291247
args.push(`codeql/${queryLanguage}-all`);
1230-
const addFormat = false;
12311248
return this.runJsonCodeQlCliCommandWithAuthentication(
12321249
["pack", "add"],
12331250
args,
12341251
`Adding and installing ${queryLanguage} pack dependency.`,
1235-
addFormat,
1252+
{
1253+
addFormat: false,
1254+
},
12361255
);
12371256
}
12381257

0 commit comments

Comments
 (0)