Skip to content

Commit b961a7a

Browse files
committed
Extract RunOptions
1 parent 23003ec commit b961a7a

1 file changed

Lines changed: 34 additions & 37 deletions

File tree

  • extensions/ql-vscode/src/codeql-cli

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ type VersionChangedListener = (
217217
newVersionAndFeatures: VersionAndFeatures | undefined,
218218
) => void;
219219

220+
type RunOptions = {
221+
/**
222+
* Used to output progress messages, e.g. to the status bar.
223+
*/
224+
progressReporter?: ProgressReporter;
225+
/**
226+
* Used for responding to interactive output on stdout/stdin.
227+
*/
228+
onLine?: OnLineCallback;
229+
/**
230+
* If true, don't print logs to the CodeQL extension log.
231+
*/
232+
silent?: boolean;
233+
};
234+
235+
type JsonRunOptions = RunOptions & {
236+
/**
237+
* Whether to add commandline arguments to specify the format as JSON.
238+
*/
239+
addFormat?: boolean;
240+
};
241+
220242
/**
221243
* This class manages a cli server started by `codeql execute cli-server` to
222244
* run commands without the overhead of starting a new java
@@ -691,21 +713,14 @@ export class CodeQLCliServer implements Disposable {
691713
* @param description Description of the action being run, to be shown in log and error messages.
692714
* @param progressReporter Used to output progress messages, e.g. to the status bar.
693715
* @param onLine Used for responding to interactive output on stdout/stdin.
716+
* @param silent If true, don't print logs to the CodeQL extension log.
694717
* @returns The contents of the command's stdout, if the command succeeded.
695718
*/
696719
runCodeQlCliCommand(
697720
command: string[],
698721
commandArgs: string[],
699722
description: string,
700-
{
701-
progressReporter,
702-
onLine,
703-
silent = false,
704-
}: {
705-
progressReporter?: ProgressReporter;
706-
onLine?: OnLineCallback;
707-
silent?: boolean;
708-
} = {},
723+
{ progressReporter, onLine, silent = false }: RunOptions = {},
709724
): Promise<string> {
710725
if (progressReporter) {
711726
progressReporter.report({ message: description });
@@ -743,36 +758,26 @@ export class CodeQLCliServer implements Disposable {
743758
* @param description Description of the action being run, to be shown in log and error messages.
744759
* @param addFormat Whether or not to add commandline arguments to specify the format as JSON.
745760
* @param progressReporter Used to output progress messages, e.g. to the status bar.
746-
* @param onLine Used for responding to interactive output on stdout/stdin.
747761
* @returns The contents of the command's stdout, if the command succeeded.
748762
*/
749763
async runJsonCodeQlCliCommand<OutputType>(
750764
command: string[],
751765
commandArgs: string[],
752766
description: string,
753-
{
754-
addFormat = true,
755-
progressReporter,
756-
onLine,
757-
silent = false,
758-
}: {
759-
addFormat?: boolean;
760-
progressReporter?: ProgressReporter;
761-
onLine?: OnLineCallback;
762-
silent?: boolean;
763-
} = {},
767+
{ addFormat = true, ...runOptions }: JsonRunOptions = {},
764768
): Promise<OutputType> {
765769
let args: string[] = [];
766770
if (addFormat) {
767771
// Add format argument first, in case commandArgs contains positional parameters.
768772
args = args.concat(["--format", "json"]);
769773
}
770774
args = args.concat(commandArgs);
771-
const result = await this.runCodeQlCliCommand(command, args, description, {
772-
progressReporter,
773-
onLine,
774-
silent,
775-
});
775+
const result = await this.runCodeQlCliCommand(
776+
command,
777+
args,
778+
description,
779+
runOptions,
780+
);
776781
try {
777782
return JSON.parse(result) as OutputType;
778783
} catch (err) {
@@ -800,21 +805,14 @@ export class CodeQLCliServer implements Disposable {
800805
* @param command The `codeql` command to be run, provided as an array of command/subcommand names.
801806
* @param commandArgs The arguments to pass to the `codeql` command.
802807
* @param description Description of the action being run, to be shown in log and error messages.
803-
* @param addFormat Whether or not to add commandline arguments to specify the format as JSON.
804-
* @param progressReporter Used to output progress messages, e.g. to the status bar.
808+
* @param runOptions Options for running the command.
805809
* @returns The contents of the command's stdout, if the command succeeded.
806810
*/
807811
async runJsonCodeQlCliCommandWithAuthentication<OutputType>(
808812
command: string[],
809813
commandArgs: string[],
810814
description: string,
811-
{
812-
addFormat,
813-
progressReporter,
814-
}: {
815-
addFormat?: boolean;
816-
progressReporter?: ProgressReporter;
817-
} = {},
815+
runOptions: Omit<JsonRunOptions, "onLine"> = {},
818816
): Promise<OutputType> {
819817
const accessToken = await this.app.credentials.getExistingAccessToken();
820818

@@ -825,8 +823,7 @@ export class CodeQLCliServer implements Disposable {
825823
[...extraArgs, ...commandArgs],
826824
description,
827825
{
828-
addFormat,
829-
progressReporter,
826+
...runOptions,
830827
onLine: async (line) => {
831828
if (line.startsWith("Enter value for --github-auth-stdin")) {
832829
try {

0 commit comments

Comments
 (0)