import { exec as execCallback } from 'child_process'; import { promisify } from 'util'; // Use the same exec pattern as the existing ArgoCD implementation const exec = promisify(execCallback); /** * Checks if ArgoCD CLI is available using the same pattern as the existing ArgoCD service * @returns true if ArgoCD CLI is installed, false otherwise */ export async function checkArgoCDCli(): Promise { try { // Use the same command pattern as in sync.service.ts const command = 'argocd version --client'; console.log(`Checking ArgoCD CLI availability: ${command}`); const { stderr } = await exec(command); if (stderr && stderr.trim()) { console.warn(`ArgoCD CLI check warnings: ${stderr}`); } return true; } catch (error) { return false; } } /** * Checks all required CLIs and fails fast if any are missing * Only logs errors when CLIs are not available */ export async function checkClis( logger?: { error: (msg: string) => void } ): Promise { const log = logger || console; const isArgoCDAvailable = await checkArgoCDCli(); if (!isArgoCDAvailable) { const errorMessage = `ArgoCD CLI is required but not found.\n\n`; log.error(errorMessage); throw new Error(errorMessage); } }