#compdef shfmt

_shfmt() {
  typeset -A opt_args
  typeset -a _arguments_options
  local ret=1

  local context curcontext=$curcontext state line
  _arguments -s -S -C \
    {-l,--list}'[List files whose formatting differs from shfmt'\''s]:list:(0)' \
    {-w,--write}'[Write result to file instead of stdout]' \
    {-d,--diff}'[Error with a diff when the formatting differs]' \
    '--apply-ignore[Always apply EditorConfig ignore rules]' \
    '--filename[Provide a name for the standard input file]' \
    {-ln,--language-dialect}'[bash/posix/mksh/bats, default "auto"]:string:(bash posix mksh bats auto)' \
    {-p,--posix}'[Shorthand for -ln=posix]' \
    {-s,--simplify}'[Simplify the code]' \
    {-i,--indent}'[0 for tabs (default), >0 for number of spaces]:uint:' \
    {-bn,--binary-next-line}'[Binary ops like && and | may start a line]' \
    {-ci,--case-indent}'[Switch cases will be indented]' \
    {-sr,--space-redirects}'[Redirect operators will be followed by a space]' \
    {-kp,--keep-padding}'[Keep column alignment paddings]' \
    {-fn,--func-next-line}'[Function opening braces are placed on a separate line]' \
    {-f,--find}'[Recursively find all shell files and print the paths]' \
    '--to-json[Print syntax tree to stdout as a typed JSON]' \
    '--from-json[Read syntax tree from stdin as a typed JSON]' \
    '*:file:_files' \
    && ret=0

  return $ret
}

_shfmt "$@"
