# pkf fish completion.
# Suggested install:  pkf completion fish > ~/.config/fish/completions/pkf.fish

function __pkf_tasks
    pkf list 2>/dev/null | awk '{print $1}'
end

# Subcommands when no subcommand has been picked yet.
complete -c pkf -f -n '__fish_use_subcommand' -a init      -d 'write a starter Taskfile.pkl'
complete -c pkf -f -n '__fish_use_subcommand' -a list      -d 'list declared tasks'
complete -c pkf -f -n '__fish_use_subcommand' -a describe  -d 'show a single task surface'
complete -c pkf -f -n '__fish_use_subcommand' -a info      -d 'structured snapshot of the Taskfile'
complete -c pkf -f -n '__fish_use_subcommand' -a run       -d 'run one or more tasks'
complete -c pkf -f -n '__fish_use_subcommand' -a up        -d 'supervise long-running services'
complete -c pkf -f -n '__fish_use_subcommand' -a doctor    -d 'diagnose pkfire setup'
complete -c pkf -f -n '__fish_use_subcommand' -a lint      -d 'detect Taskfile issues'
complete -c pkf -f -n '__fish_use_subcommand' -a format    -d 'pkl format -w wrapper'
complete -c pkf -f -n '__fish_use_subcommand' -a hooks     -d 'manage .git/hooks shims'
complete -c pkf -f -n '__fish_use_subcommand' -a affected  -d 'run tasks whose inputs changed since <ref>'
complete -c pkf -f -n '__fish_use_subcommand' -a clean     -d 'remove declared outputs'
complete -c pkf -f -n '__fish_use_subcommand' -a cache     -d 'inspect / clean the local CAS'
complete -c pkf -f -n '__fish_use_subcommand' -a completion -d 'emit shell completion script'
complete -c pkf -f -n '__fish_use_subcommand' -a graph     -d 'emit DAG (dot / mermaid / tree / json)'
complete -c pkf -f -n '__fish_use_subcommand' -a explain   -d 'dump or compare inputs to the action key'
complete -c pkf -f -n '__fish_use_subcommand' -a migrate   -d 'rewrite Taskfile schema version'
complete -c pkf -f -n '__fish_use_subcommand' -a pkl-cache -d 'warm the local Pkl package cache'
complete -c pkf -f -n '__fish_use_subcommand' -a version   -d 'print pkf version'
complete -c pkf -f -n '__fish_use_subcommand' -a help      -d 'show usage'

# Dynamic task names for the subcommands that take them.
complete -c pkf -f -n '__fish_seen_subcommand_from run affected clean up explain describe' -a '(__pkf_tasks)'

# Nested subcommand completions.
complete -c pkf -f -n '__fish_seen_subcommand_from hooks' -a 'install uninstall list'
complete -c pkf -f -n '__fish_seen_subcommand_from cache' -a 'stats prune rm clear'
complete -c pkf -f -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish'
complete -c pkf -f -n '__fish_seen_subcommand_from list' -l color -a 'auto always never'
complete -c pkf -f -n '__fish_seen_subcommand_from list' -s v -l verbose -d 'show cmd preview and deps'
complete -c pkf -f -n '__fish_seen_subcommand_from list' -l long -d 'show compact audit table'
complete -c pkf -f -n '__fish_seen_subcommand_from list' -l json -d 'emit machine-readable output'
complete -c pkf -f -n '__fish_seen_subcommand_from list' -l all -d 'include internal tasks'
complete -c pkf -f -n '__fish_seen_subcommand_from list' -l unsorted -d 'use declaration order'
complete -c pkf -f -n '__fish_seen_subcommand_from list' -l source-order -d 'use declaration order'
complete -c pkf -f -n '__fish_seen_subcommand_from lint' -l json -d 'emit machine-readable output'
complete -c pkf -f -n '__fish_seen_subcommand_from lint' -l fix -d 'apply safe fixes'
complete -c pkf -f -n '__fish_seen_subcommand_from lint' -l dry-run -d 'show fixes without writing files'
complete -c pkf -f -n '__fish_seen_subcommand_from doctor' -l json -d 'emit machine-readable output'
complete -c pkf -f -n '__fish_seen_subcommand_from doctor' -l fix -d 'apply safe fixes'
complete -c pkf -f -n '__fish_seen_subcommand_from doctor' -l dry-run -d 'show fixes without writing files'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l since -d 'git ref to diff against'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l files -d 'simulate changed file paths'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l explain -d 'show matching input patterns'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l check -d 'run workflowTests'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l dry-run -d 'preview plan without running'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l no-cache -d 'disable cache for this run'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l refresh -d 'skip lookup but store outputs'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l timing -d 'print task durations'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l quiet -d 'suppress per-task log lines'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l keep-going -d 'do not stop on first failure'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l profile -d 'profile name for cache keys'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -l watch -d 'recompute affected set on change'
complete -c pkf -f -n '__fish_seen_subcommand_from affected' -s j -l jobs -d 'max concurrent tasks'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l watch -d 're-run on input changes'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l dry-run -d 'preview plan without running'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l print-hash -d 'print action keys and exit'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l explain-cache -d 'explain cache decisions and exit'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l no-cache -d 'disable cache for this run'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l refresh -d 'skip lookup but store outputs'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l timing -d 'print task durations'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l quiet -d 'suppress per-task log lines'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l keep-going -d 'do not stop on first failure'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l profile -d 'profile name for cache keys'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l on-fail -d 'action on task failure'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -l remote-only -d 'consult only remote cache'
complete -c pkf -f -n '__fish_seen_subcommand_from run' -s j -l jobs -d 'max concurrent tasks'

# `pkf graph --format <TAB>`.
complete -c pkf -f -n '__fish_seen_subcommand_from graph' -l format -a 'dot mermaid tree json'
complete -c pkf -f -n '__fish_seen_subcommand_from graph' -l json -d 'emit machine-readable output'
complete -c pkf -f -n '__fish_seen_subcommand_from graph' -l target -d 'render only one task subgraph'
complete -c pkf -f -n '__fish_seen_subcommand_from graph' -l all -d 'include internal tasks'
complete -c pkf -f -n '__fish_seen_subcommand_from graph' -l unsorted -d 'use declaration order'
complete -c pkf -f -n '__fish_seen_subcommand_from graph' -l source-order -d 'use declaration order'
complete -c pkf -f -n '__fish_seen_subcommand_from graph' -l depth -d 'limit dependency traversal'

complete -c pkf -f -n '__fish_seen_subcommand_from explain' -s f -l file -d 'path to Taskfile.pkl'
complete -c pkf -f -n '__fish_seen_subcommand_from explain' -l diff -d 'compare against another Taskfile.pkl'
complete -c pkf -f -n '__fish_seen_subcommand_from describe' -s f -l file -d 'path to Taskfile.pkl'
complete -c pkf -f -n '__fish_seen_subcommand_from describe' -l json -d 'emit machine-readable output'
complete -c pkf -f -n '__fish_seen_subcommand_from info' -s f -l file -d 'path to Taskfile.pkl'
complete -c pkf -f -n '__fish_seen_subcommand_from info' -l json -d 'emit machine-readable output'
complete -c pkf -f -n '__fish_seen_subcommand_from info' -l all -d 'include internal tasks'
complete -c pkf -f -n '__fish_seen_subcommand_from migrate' -s f -l file -d 'path to Taskfile.pkl'
complete -c pkf -f -n '__fish_seen_subcommand_from migrate' -l to -d 'target schema version'
complete -c pkf -f -n '__fish_seen_subcommand_from migrate' -l dry-run -d 'preview rewrite without writing'
complete -c pkf -f -n '__fish_seen_subcommand_from migrate' -l skip-verify -d 'skip post-migration pkl eval'
complete -c pkf -f -n '__fish_seen_subcommand_from pkl-cache' -a warm -d 'pre-evaluate Pkl files'
complete -c pkf -f -n '__fish_seen_subcommand_from pkl-cache' -s f -l file -d 'path to Taskfile.pkl'
