export async function getCli()

in vscode/qodana/src/core/cli/cliDownloader.ts [16:50]


export async function getCli(context: vscode.ExtensionContext): Promise<string | undefined> {
    let cliFromSettings = context.globalState.get<string | undefined>(GS_CLI_SETTING);
    let cliVerFromSettings = context.globalState.get<string | undefined>(GS_VER_SETTING);
    if (cliFromSettings) {
        try {
            await fs.promises.access(cliFromSettings);
        } catch (e) {
            await context.globalState.update(GS_VER_SETTING, undefined);
            await context.globalState.update(GS_CLI_SETTING, undefined);
            cliFromSettings = undefined;
        }
    }
    if (cliFromSettings && cliVerFromSettings === version) {
        return cliFromSettings;
    }

    let decision = await vscode.window.showErrorMessage(CLI_DOWNLOAD_CONFIRMATION, YES, NO);
    if (decision === YES) {
        let downloadedCliArchDir = path.join(context.globalStorageUri.fsPath, Math.random().toString(36).substring(7));
        let downloadedCliDir = path.join(context.globalStorageUri.fsPath, Math.random().toString(36).substring(7));
        await fs.promises.mkdir(downloadedCliArchDir, { recursive: true });
        await fs.promises.mkdir(downloadedCliDir, { recursive: true });
        let cli = await downloadAndUnpackCli(downloadedCliArchDir, downloadedCliDir);
        if (cli) {
            telemetry.cliDownloaded();
            await context.globalState.update(GS_VER_SETTING, version);
            await context.globalState.update(GS_CLI_SETTING, cli);
            vscode.window.showInformationMessage(cliSuccessfullyExtracted(cli));
            return cli;
        }
    } else if (cliFromSettings) {
        return cliFromSettings;
    }
    return undefined;
}