#compdef _yq yq


function _yq {
  local -a commands

  _arguments -C \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]' \
    '(-V --version)'{-V,--version}'[Print version information and quit]' \
    "1: :->cmnds" \
    "*::arg:->args"

  case $state in
  cmnds)
    commands=(
      "compare:yq x [--prettyPrint/-P] dataA.yaml dataB.yaml 'b.e(name==fr*).value'"
      "delete:yq d [--inplace/-i] [--doc/-d index] sample.yaml 'b.e(name==fred)'"
      "help:Help about any command"
      "merge:yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] [--arrayMerge/-a strategy] sample.yaml sample2.yaml"
      "new:yq n [--script/-s script_file] a.b.c newValue"
      "prefix:yq p [--inplace/-i] [--doc/-d index] sample.yaml a.b.c"
      "read:yq r [--printMode/-p pv] sample.yaml 'b.e(name==fr*).value'"
      "shell-completion:Generates shell completion scripts"
      "validate:yq v sample.yaml"
      "write:yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml 'b.e(name==fr*).value' newValue"
    )
    _describe "command" commands
    ;;
  esac

  case "$words[1]" in
  compare)
    _yq_compare
    ;;
  delete)
    _yq_delete
    ;;
  help)
    _yq_help
    ;;
  merge)
    _yq_merge
    ;;
  new)
    _yq_new
    ;;
  prefix)
    _yq_prefix
    ;;
  read)
    _yq_read
    ;;
  shell-completion)
    _yq_shell-completion
    ;;
  validate)
    _yq_validate
    ;;
  write)
    _yq_write
    ;;
  esac
}

function _yq_compare {
  _arguments \
    '(-D --defaultValue)'{-D,--defaultValue}'[default value printed when there are no results]:' \
    '(-d --doc)'{-d,--doc}'[process document index number (0 based, * for all documents)]:' \
    '(-X --explodeAnchors)'{-X,--explodeAnchors}'[explode anchors]' \
    '(-p --printMode)'{-p,--printMode}'[print mode (v (values, default), p (paths), pv (path and value pairs)]:' \
    '--stripComments[strip comments out before comparing]' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_delete {
  _arguments \
    '(-d --doc)'{-d,--doc}'[process document index number (0 based, * for all documents)]:' \
    '(-i --inplace)'{-i,--inplace}'[update the yaml file inplace]' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_help {
  _arguments \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_merge {
  _arguments \
    '(-a --arrays)'{-a,--arrays}'[array merge strategy (update/append/overwrite)
update: recursively update arrays by their index
append: concatenate arrays together
overwrite: replace arrays
]:' \
    '(-c --autocreate)'{-c,--autocreate}'[automatically create any missing entries]' \
    '--comments[comments merge strategy (setWhenBlank/ignore/append/overwrite)
setWhenBlank: set comment if the original document has no comment at that node
ignore: leave comments as-is in the original
append: append comments together
overwrite: overwrite comments completely
]:' \
    '(-d --doc)'{-d,--doc}'[process document index number (0 based, * for all documents)]:' \
    '(-i --inplace)'{-i,--inplace}'[update the yaml file inplace]' \
    '(-x --overwrite)'{-x,--overwrite}'[update the yaml file by overwriting existing values]' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_new {
  _arguments \
    '--anchorName[anchor name]:' \
    '--makeAlias[create an alias using the value as the anchor name]' \
    '(-s --script)'{-s,--script}'[yaml script for creating yaml]:' \
    '--style[formatting style of the value: single, double, folded, flow, literal, tagged]:' \
    '(-t --tag)'{-t,--tag}'[set yaml tag (e.g. !!int)]:' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_prefix {
  _arguments \
    '(-d --doc)'{-d,--doc}'[process document index number (0 based, * for all documents)]:' \
    '(-i --inplace)'{-i,--inplace}'[update the yaml file inplace]' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_read {
  _arguments \
    '(-c --collect)'{-c,--collect}'[collect results into array]' \
    '(-D --defaultValue)'{-D,--defaultValue}'[default value printed when there are no results]:' \
    '(-d --doc)'{-d,--doc}'[process document index number (0 based, * for all documents)]:' \
    '(-e --exitStatus)'{-e,--exitStatus}'[set exit status if no matches are found]' \
    '(-X --explodeAnchors)'{-X,--explodeAnchors}'[explode anchors]' \
    '(-l --length)'{-l,--length}'[print length of results]' \
    '(-p --printMode)'{-p,--printMode}'[print mode (v (values, default), p (paths), pv (path and value pairs)]:' \
    '--stripComments[print yaml without any comments]' \
    '--unwrapScalar[unwrap scalar, print the value with no quotes, colors or comments]' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_shell-completion {
  _arguments \
    '(-h --help)'{-h,--help}'[help for shell-completion]' \
    '(-V --variation)'{-V,--variation}'[shell variation: bash (default), zsh, fish, powershell]:' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_validate {
  _arguments \
    '(-d --doc)'{-d,--doc}'[process document index number (0 based, * for all documents)]:' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

function _yq_write {
  _arguments \
    '--anchorName[anchor name]:' \
    '(-d --doc)'{-d,--doc}'[process document index number (0 based, * for all documents)]:' \
    '(-f --from)'{-f,--from}'[yaml file for updating yaml (as-is)]:' \
    '(-i --inplace)'{-i,--inplace}'[update the yaml file inplace]' \
    '--makeAlias[create an alias using the value as the anchor name]' \
    '(-s --script)'{-s,--script}'[yaml script for updating yaml]:' \
    '--style[formatting style of the value: single, double, folded, flow, literal, tagged]:' \
    '(-t --tag)'{-t,--tag}'[set yaml tag (e.g. !!int)]:' \
    '(-C --colors)'{-C,--colors}'[print with colors]' \
    '(-I --indent)'{-I,--indent}'[sets indent level for output]:' \
    '(-P --prettyPrint)'{-P,--prettyPrint}'[pretty print]' \
    '(-j --tojson)'{-j,--tojson}'[output as json. By default it prints a json document in one line, use the prettyPrint flag to print a formatted doc.]' \
    '(-v --verbose)'{-v,--verbose}'[verbose mode]'
}

