#compdef portmaster
# For portmaster 2.11

local context state line array ret=1
typeset -A opt_args

_arguments -A "-*" : \
  "--force-config['make config' for all ports (must be first option)]" \
  "-C[prevents 'make clean' from being run before building]" \
  "(-F)-G[prevents recursive 'make config' (overrides --force-config)]" \
  "-H[hide details of the port build and install in a log file]" \
  "-K[prevents 'make clean' from being run after building]" \
  "(-b)-B[prevents creation of the backup package for the installed port]" \
  "(-B)-b[create and keep a backup package of an installed port]" \
  "-g[create a package of the new port]" \
  "-n[run through configure, but do not make or install any ports]" \
  "-t[recurse dependencies thoroughly, using all-depends-array]" \
  "-v[verbose output]" \
  "-w[save old shared libraries before deinstall]" \
  "-u[DEPRECATED]" \
  "-f[always rebuild ports (overrides -i)]" \
  "(-f)-i[interactive update -- ask whether to rebuild ports]" \
  "(-d)-D[no cleaning of distfiles]" \
  "(-D)-d[always clean distfiles]" \
  "-m[<arguments for the 'make' command line>]:arguments for make: " \
  "-x[<avoid building or updating ports that match this pattern>]:glob pattern to exclude from building:->pkgs" \
  "-p[specify the full path to a port directory]:port directory in /usr/ports:->ports" \
  "--show-work[array what ports are and would be installed]" \
  "-o[replace the installed port with a port from a different origin]:new port dir in /usr/ports:->ports" \
  "-r[rebuild port, and all ports that depend on it]:name/glob of port in /var/db/pkg:->pkgs" \
  "-R[used with -\[rf\] to skip ports updated on a previous run]" \
  "-a[check all ports, update as necessary]" \
  "-l[array installed ports by category]" \
  "-L[array installed ports by category, and search for updates]" \
  "-e[expunge a port via pkg_delete, and remove its distfiles]:name of port directory in /var/db/pkg:->pkgs" \
  "-s[clean out stale ports that used to be depended on]" \
  "(-G)-F[fetch distfiles only]" \
  "--clean-distfiles[offer to delete stale distfiles]" \
  "--clean-distfiles-all[delete stale distfiles without prompting]" \
  "--check-depends[cross-check and update dependency information for all ports]" \
  "--check-port-dbdir[check for stale entries in /var/db/ports]" \
  "--list-origins[list directories from /usr/ports for root and leaf ports]" \
  "(-h --help)"{-h,--help}"[display this help message]" \
  "--version[display the version number]" \
  '*:Packages and Ports:->pkgs_ports'

case "$state" in
  pkgs)
    array=("${PKG_DBDIR:-/var/db/pkg}"/*(/:t))
    _describe -t packages "installed ports" array
    ;;
  ports)
    _files -X "%Bports%b" -W "${PORTSDIR:-/usr/ports}" -/
    ;;
  pkgs_ports)
    _tags packages ports
    while _tags; do
      if _requested packages; then
        array=("${PKG_DBDIR:-/var/db/pkg}"/*(/:t))
        _describe -t packages "installed ports" array && ret=0
      fi
      if _requested ports; then
        _files -X "%Bports%b" -W "${PORTSDIR:-/usr/ports}" -/ && ret=0
      fi
      (( ret )) || return ret
    done
    ;;
esac
