#compdef awkrs aw

# Zsh completion for awkrs — awk-compatible pattern-directed scanning and processing

_awkrs_lint_values() {
  local -a vals=(
    'fatal:Treat lint warnings as fatal errors'
    'invalid:Warn about invalid constructs'
    'no-ext:Warn about non-POSIX extensions'
  )
  _describe 'lint level' vals
}

_awkrs() {
  local curcontext="$curcontext" ret=1

  _arguments -s -S \
    '-f+[Read program from file]:program file:_files' \
    '--file=[Read program from file]:program file:_files' \
    '-F+[Set field separator]:field separator:' \
    '--field-separator=[Set field separator]:field separator:' \
    '*-v+[Assign variable before execution]:var=val:' \
    '*--assign=[Assign variable before execution]:var=val:' \
    '*-e+[Program source text]:program text:' \
    '*--source=[Program source text]:program text:' \
    '*-i+[Include awk source file]:include file:_files' \
    '*--include=[Include awk source file]:include file:_files' \
    '-b[Treat characters as bytes]' \
    '--characters-as-bytes[Treat characters as bytes]' \
    '-c[Use traditional POSIX awk]' \
    '--traditional[Use traditional POSIX awk]' \
    '-C[Print copyright info]' \
    '--copyright[Print copyright info]' \
    '-d+[Dump variables to file]:dump file:_files' \
    '--dump-variables=[Dump variables to file]:dump file:_files' \
    '-D+[Debug mode with file]:debug file:_files' \
    '--debug=[Debug mode with file]:debug file:_files' \
    '-E+[Execute program from file then exit]:exec file:_files' \
    '--exec=[Execute program from file then exit]:exec file:_files' \
    '-g[Generate .pot file for i18n]' \
    '--gen-pot[Generate .pot file for i18n]' \
    '-I[Trace execution]' \
    '--trace[Trace execution]' \
    '-k[Enable CSV field parsing]' \
    '--csv[Enable CSV field parsing]' \
    '*-l+[Load shared library]:library name:' \
    '*--load=[Load shared library]:library name:' \
    '-L+[Lint level]:lint level:_awkrs_lint_values' \
    '--lint=[Lint level]:lint level:_awkrs_lint_values' \
    '-M[Enable arbitrary precision arithmetic]' \
    '--bignum[Enable arbitrary precision arithmetic]' \
    '-N[LC_NUMERIC for printf/print; $n parsing still uses .]' \
    '--use-lc-numeric[LC_NUMERIC for printf/print; $n parsing still uses .]' \
    '-n[Allow non-decimal input data]' \
    '--non-decimal-data[Allow non-decimal input data]' \
    '-o+[AST listing (awkrs format, not gawk -o)]:output file:_files' \
    '--pretty-print=[AST listing (awkrs format, not gawk -o)]:output file:_files' \
    '-O[Optimize program]' \
    '--optimize[Optimize program]' \
    '-p+[Profile summary (awkrs format, not gawk -p)]:profile file:_files' \
    '--profile=[Profile summary (awkrs format, not gawk -p)]:profile file:_files' \
    '-P[Strict POSIX mode]' \
    '--posix[Strict POSIX mode]' \
    '-r[No-op: m,n interval regex always on]' \
    '--re-interval[No-op: m,n interval regex always on]' \
    '-s[Disable optimizations]' \
    '--no-optimize[Disable optimizations]' \
    '-S[Sandbox mode (disable I/O redirections)]' \
    '--sandbox[Sandbox mode (disable I/O redirections)]' \
    '-t[Lint old-style awk constructs]' \
    '--lint-old[Lint old-style awk constructs]' \
    '*-W+[mawk-compatible option]:mawk option:(help usage version exec=)' \
    '-j+[Thread count for internal pools (default 1)]:thread count:' \
    '--threads=[Thread count for internal pools (default 1)]:thread count:' \
    '--read-ahead=[Read-ahead queue depth (lines)]:queue depth:' \
    '-h[Print help]' \
    '--help[Print help]' \
    '-V[Print version]' \
    '--version[Print version]' \
    '*:input file:_files' \
  && ret=0

  return ret
}

_awkrs "$@"
