#compdef pkgdev

typeset -a base_options
local curcontext=$curcontext state state_descr line ret=1

base_options=(
  '(- :)'{-h,--help}'[show help information and exit]'
  '(- :)'--version'[show version information and exit]'
  '(--debug --help -h)--debug[enable debugging output]'
  '(--quiet -q --verbose -v)'{-q,--quiet}'[suppress non-error output]'
  '(--verbose -v --quiet -q)'{-v,--verbose}'[show verbose output]'
  "--color[Color output]:yes/no:((y\:'yes' n\:'no'))"
)

_arguments -C \
  $base_options \
  '(-): :->command' \
  '(-)*:: :->subcommand' \
  && ret=0

case $state in
  (command)
    typeset -a subcommands

    subcommands=(
      commit:'create git commit'
      manifest:'update package manifests'
      push:'run QA checks on commits and push them'
    )

    _describe -t subcommands subcommand subcommands && ret=0

    ;;
  (subcommand)
    curcontext=${curcontext%:*}-$line[1]:

    case $line[1] in
      (commit)
        _arguments -C -A '-*' \
          $base_options \
          {'(--bug)-b','(-b)--bug'}'[add Bug tag for a given Gentoo or upstream bug]:bug ID or URL' \
          {'(--closes)-c','(-c)--closes'}'[add Closes tag for a given Gentoo bug or upstream PR URL]:bug ID or URL' \
          {'(--dry-run)-n','(-n)--dry-run'}'[pretend to create commit]' \
          {'(--scan)-s','(-s)--scan'}'[run pkgcheck against staged changes]' \
          {'(--ask)-A','(-A)--ask'}'[confirm creating commit with QA errors]' \
          '--mangle[forcibly enable/disable file mangling]' \
          \*{--message,-m}'[specify commit message]:message' \
          {'(--message-template)-M','(-M)--message-template'}'[use commit message template from specified file]:template:_files' \
          {'(--update)-u','(-u)--update'}'[stage all changed files]' \
          {'(--all)-a','(-a)--all'}'[stage all changed/new/removed files]' \
          && ret=0
        ;;
      (manifest)
        _arguments -C -A '-*' \
          $base_options \
          {'(--force)-f','(-f)--force'}'[forcibly remanifest packages]' \
          {'(--mirrors)-m','(-m)--mirrors'}'[enable fetching from Gentoo mirrors]' \
          && ret=0
        ;;
      (push)
        _arguments -C -A '-*' \
          $base_options \
          {'(--ask)-A','(-A)--ask'}'[confirm pushing commits with QA errors]' \
          {'(--dry-run)-n','(-n)--dry-run'}'[pretend to push commits]' \
          && ret=0
        ;;
      (*)
        _nothing
        ;;
    esac
    ;;
esac

return ret

# vim: set et sw=2 ts=2 ft=zsh:
