---
source: lib/src/complete/powershell.rs
expression: "complete_powershell(&CompleteOptions\n{\n    usage_bin: \"usage\".to_string(), shell: \"powershell\".to_string(), bin:\n    \"mycli\".to_string(), cache_key: None, spec: None, usage_cmd:\n    Some(\"mycli complete --usage\".to_string()), include_bash_completion_lib:\n    false, source_file: None,\n})"
---
# @generated by usage-cli from usage spec

if (-not (Get-Command 'usage' -ErrorAction SilentlyContinue)) {
    Write-Warning "Error: usage CLI not found. This is required for completions to work in mycli."
    Write-Warning "See https://usage.jdx.dev for more information."
    return
}

Register-ArgumentCompleter -Native -CommandName 'mycli' -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)

    $tmpDir = if ($env:TEMP) { $env:TEMP } else { [System.IO.Path]::GetTempPath() }
    $specFile = Join-Path $tmpDir "usage__usage_spec_mycli.kdl"

    mycli complete --usage | Out-File -FilePath $specFile -Encoding utf8

    $words = $commandAst.CommandElements | ForEach-Object { $_.ToString() }
    if ($words.Count -lt 1) {
        $words = @('mycli')
    }

    $completions = & 'usage' complete-word --shell powershell -f "$specFile" -- @words $wordToComplete 2>$null

    if ($completions) {
        $completions | ForEach-Object {
            $parts = $_ -split "`t", 2
            $completion = $parts[0]
            $description = if ($parts.Count -gt 1) { $parts[1] } else { '' }

            [System.Management.Automation.CompletionResult]::new(
                $completion,
                $completion,
                'ParameterValue',
                $description
            )
        }
    }
}
