11import { EOL } from "os" ;
22import { spawn } from "child-process-promise" ;
33import type { ChildProcessWithoutNullStreams } from "child_process" ;
4- import { execFile , spawn as spawnChildProcess } from "child_process" ;
4+ import { spawn as spawnChildProcess } from "child_process" ;
55import { readFile } from "fs-extra" ;
66import { delimiter , dirname , join } from "path" ;
77import type { Log } from "sarif" ;
88import { SemVer } from "semver" ;
99import type { Readable } from "stream" ;
1010import tk from "tree-kill" ;
11- import { promisify } from "util" ;
1211import type { CancellationToken , Disposable , Uri } from "vscode" ;
1312
1413import type {
@@ -21,7 +20,6 @@ import type { DistributionProvider } from "./distribution";
2120import { FindDistributionResultKind } from "./distribution" ;
2221import {
2322 assertNever ,
24- getChildProcessErrorMessage ,
2523 getErrorMessage ,
2624 getErrorStack ,
2725} from "../common/helpers-pure" ;
@@ -35,6 +33,7 @@ import type { App } from "../common/app";
3533import { QueryLanguage } from "../common/query-language" ;
3634import { LINE_ENDINGS , splitStreamAtSeparators } from "../common/split-stream" ;
3735import type { Position } from "../query-server/messages" ;
36+ import { LOGGING_FLAGS } from "./cli-command" ;
3837
3938/**
4039 * The version of the SARIF format that we are using.
@@ -46,11 +45,6 @@ const SARIF_FORMAT = "sarifv2.1.0";
4645 */
4746const CSV_FORMAT = "csv" ;
4847
49- /**
50- * Flags to pass to all cli commands.
51- */
52- const LOGGING_FLAGS = [ "-v" , "--log-to-stderr" ] ;
53-
5448/**
5549 * The expected output of `codeql resolve queries --format bylanguage`.
5650 */
@@ -1632,45 +1626,6 @@ export function spawnServer(
16321626 return child ;
16331627}
16341628
1635- /**
1636- * Runs a CodeQL CLI command without invoking the CLI server, returning the output as a string.
1637- * @param codeQlPath The path to the CLI.
1638- * @param command The `codeql` command to be run, provided as an array of command/subcommand names.
1639- * @param commandArgs The arguments to pass to the `codeql` command.
1640- * @param description Description of the action being run, to be shown in log and error messages.
1641- * @param logger Logger to write command log messages, e.g. to an output channel.
1642- * @param progressReporter Used to output progress messages, e.g. to the status bar.
1643- * @returns The contents of the command's stdout, if the command succeeded.
1644- */
1645- export async function runCodeQlCliCommand (
1646- codeQlPath : string ,
1647- command : string [ ] ,
1648- commandArgs : string [ ] ,
1649- description : string ,
1650- logger : Logger ,
1651- progressReporter ?: ProgressReporter ,
1652- ) : Promise < string > {
1653- // Add logging arguments first, in case commandArgs contains positional parameters.
1654- const args = command . concat ( LOGGING_FLAGS ) . concat ( commandArgs ) ;
1655- const argsString = args . join ( " " ) ;
1656- try {
1657- if ( progressReporter !== undefined ) {
1658- progressReporter . report ( { message : description } ) ;
1659- }
1660- void logger . log (
1661- `${ description } using CodeQL CLI: ${ codeQlPath } ${ argsString } ...` ,
1662- ) ;
1663- const result = await promisify ( execFile ) ( codeQlPath , args ) ;
1664- void logger . log ( result . stderr ) ;
1665- void logger . log ( "CLI command succeeded." ) ;
1666- return result . stdout ;
1667- } catch ( err ) {
1668- throw new Error (
1669- `${ description } failed: ${ getChildProcessErrorMessage ( err ) } ` ,
1670- ) ;
1671- }
1672- }
1673-
16741629/**
16751630 * Log a text stream to a `Logger` interface.
16761631 * @param stream The stream to log.
0 commit comments