Private/Invoke-CliBackend.ps1

function Invoke-CliBackend {
    <#
    .SYNOPSIS
        Adapter that dispatches pack or analyze to either uipcli or uipathcli.
 
    .NOTES
        uipathcli flag names verified against `uipathcli --help` from
        https://github.com/UiPath/uipathcli releases. Update if the Go CLI
        changes its argument interface.
    #>

    param(
        [ValidateSet('pack', 'analyze')]
        [string]   $Op,

        [ValidateSet('uipcli', 'uipathcli')]
        [string]   $Backend,

        [string]   $UipcliExe,
        [string]   $UipathcliExe,
        [string]   $ProjectJson,
        [string]   $OutputDir    = '',   # pack only
        [string[]] $ExtraArgs    = @()
    )

    if ($Backend -eq 'uipcli') {
        switch ($Op) {
            'pack' {
                $packArgs = @('package', 'pack', $ProjectJson, '-o', $OutputDir)
                if ($env:UIPATH_DISABLE_TELEMETRY) { $packArgs += '--disableTelemetry' }
                if ($ExtraArgs.Count -gt 0) { $packArgs += $ExtraArgs }
                return Invoke-UipcliPack -UipcliExe $UipcliExe -PackArgs $packArgs
            }
            'analyze' {
                $analyzeArgs = @('package', 'analyze', $ProjectJson)
                if ($ExtraArgs.Count -gt 0) { $analyzeArgs += $ExtraArgs }
                return Invoke-UipathcliCommand -UipathcliExe $UipcliExe -CliArgs $analyzeArgs
            }
        }
    } else {
        # uipathcli (Go binary) — operates on the project folder, not the .json file
        $projectDir = Split-Path $ProjectJson -Parent
        switch ($Op) {
            'pack' {
                $packArgs = @('package', 'pack', '--project-path', $projectDir, '--output-folder', $OutputDir)
                if ($ExtraArgs.Count -gt 0) { $packArgs += $ExtraArgs }
                return Invoke-UipathcliCommand -UipathcliExe $UipathcliExe -CliArgs $packArgs
            }
            'analyze' {
                $analyzeArgs = @('analyze', '--project-path', $projectDir)
                if ($ExtraArgs.Count -gt 0) { $analyzeArgs += $ExtraArgs }
                return Invoke-UipathcliCommand -UipathcliExe $UipathcliExe -CliArgs $analyzeArgs
            }
        }
    }
}