export async function installCli()

in src/shared/utilities/cliUtils.ts [77:172]


export async function installCli(
    cli: AwsClis,
    confirm: boolean,
    window: Window = Window.vscode()
): Promise<string | undefined> {
    const cliToInstall = AWS_CLIS[cli]
    if (!cliToInstall) {
        throw new InstallerError(`Invalid not found for CLI: ${cli}`)
    }
    let result: telemetry.Result = 'Succeeded'

    let tempDir: string | undefined
    const manualInstall = localize('AWS.cli.manualInstall', 'Install manually...')
    try {
        const install = localize('AWS.generic.install', 'Install')
        const selection = !confirm
            ? install
            : await window.showInformationMessage(
                  localize(
                      'AWS.cli.installCliPrompt',
                      '{0} could not find {1} CLI. Install a local copy?',
                      localize('AWS.channel.aws.toolkit', '{0} Toolkit', getIdeProperties().company),
                      cliToInstall.name
                  ),
                  install,
                  manualInstall
              )

        if (selection !== install) {
            if (selection === manualInstall) {
                vscode.env.openExternal(vscode.Uri.parse(cliToInstall.manualInstallLink))
            }
            result = 'Cancelled'

            return undefined
        }

        const timeout = new Timeout(600000)
        const progress = await showMessageWithCancel(
            localize('AWS.cli.installProgress', 'Installing: {0} CLI', cliToInstall.name),
            timeout
        )

        tempDir = await makeTemporaryToolkitFolder()
        let cliPath: string
        try {
            switch (cli) {
                case 'session-manager-plugin':
                    cliPath = await installSsmCli(tempDir, progress)
                    break
                default:
                    throw new InstallerError(`Invalid not found for CLI: ${cli}`)
            }
        } finally {
            timeout.complete()
        }
        // validate
        if (!(await hasCliCommand(cliToInstall, false))) {
            throw new InstallerError('Could not verify installed CLIs')
        }

        return cliPath
    } catch (err) {
        result = 'Failed'

        window
            .showErrorMessage(
                localize('AWS.cli.failedInstall', 'Installation of the {0} CLI failed.', cliToInstall.name),
                manualInstall
            )
            .then(button => {
                if (button === manualInstall) {
                    vscode.env.openExternal(vscode.Uri.parse(cliToInstall.manualInstallLink))
                }
            })

        throw err
    } finally {
        if (tempDir) {
            getLogger().info('Cleaning up installer...')
            // nonblocking: use `then`
            tryRemoveFolder(tempDir).then(success => {
                if (success) {
                    getLogger().info('Removed installer.')
                } else {
                    getLogger().error(`Failed to clean up installer in temp directory: ${tempDir}`)
                }
            })
        }

        telemetry.recordAwsToolInstallation({
            result,
            toolId: cli,
        })
    }
}