import { commands , Uri , window } from 'vscode' ; import { CommandId } from './commands' ; import { installFluxCli } from './commands/installFluxCli' ; import { Errorable } from './errorable' ; import { extensionState } from './extensionState' ; import { shell } from './shell' ; import { parseJson } from './utils/jsonUtils' ; export async function getKubectlVersion ( ) { const shellResult = await shell . exec ( 'kubectl version --short' ) ; if ( shellResult ?. code === 0 ) { return shellResult . stdout ; } } interface AzureVersion { 'azure-cli' : string ; 'azure-cli-core' : string ; 'azure-cli-telemetry' : string ; 'extensions' : { 'k8s-configuration' : string ; 'k8s-extension' : string ; } ; } export async function getAzureVersion ( ) { const shellResult = await shell . exec ( 'az version' ) ; if ( shellResult ?. code === 0 ) { return parseJson ( shellResult . stdout ) ; } } see https export async function getFluxVersion ( ) { const shellResult = await shell . exec ( 'flux --version' ) ; if ( shellResult ?. code === 0 ) { const fluxVersion = shellResult . stdout . slice ( 13 ) . trim ( ) ; extensionState . set ( 'fluxVersion' , fluxVersion ) ; return fluxVersion ; } } /**
 * Show notification with button to install flux
 * (only when flux was not found).
 */ export async function promptToInstallFlux ( ) { const fluxVersion = await getFluxVersion ( ) ; if ( ! fluxVersion ) { showInstallFluxNotification ( ) ; return { succeeded : false , error : [ 'Flux not found' ] , } ; } else { return { succeeded : true , result : null , } ; } } async function showInstallFluxNotification ( ) { const installButton = 'Install Flux' ; const pressedButton = await window . showErrorMessage ( 'Please install flux CLI to use GitOps Tools.' , installButton ) ; if ( pressedButton === installButton ) { installFluxCli ( ) ; } } see https export async function checkFluxPrerequisites ( ) { const prerequisiteShellResult = await shell . execWithOutput ( 'flux check --pre' , { revealOutputView : false } ) ; if ( prerequisiteShellResult ?. code !== 0 ) { const showOutput = 'Show Output' ; const showOutputConfirm = await window . showWarningMessage ( 'Flux prerequisites check failed.' , showOutput ) ; if ( showOutput === showOutputConfirm ) { commands . executeCommand ( CommandId . ShowOutputChannel ) ; } } } /**
 * Return git version or undefined depending
 * on whether or not git was found on the user machine.
 */ export async function getGitVersion ( ) { const gitVersionShellResult = await shell . execWithOutput ( 'git --version' , { revealOutputView : false } ) ; if ( gitVersionShellResult ?. code === 0 ) { return gitVersionShellResult . stdout . slice ( 'git version ' . length ) ; } } /**
 * Check if git is found and prompt to install it (if needed).
 */ export async function checkGitVersion ( ) { const gitVersion = await getGitVersion ( ) ; if ( gitVersion === undefined ) { const installButton = 'Install' ; const confirm = await window . showErrorMessage ( 'Please install Git.' , installButton ) ; if ( confirm === installButton ) { commands . executeCommand ( 'vscode.open' , Uri . parse ( 'https://git-scm.com/downloads' ) ) ; } } else { return gitVersion ; } }