#compdef github gh
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for Github gem 0.6.2 (https://github.com/defunkt/github-gem).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * Julien Nicoulaud (https://github.com/nicoulaj)
#
# ------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------


typeset -A opt_args
local context state line curcontext="$curcontext"

_github() {
  local ret=1

  _arguments -C \
    '1:cmd:->cmds' \
    '*::arg:->args' \
  && ret=0

  case "$state" in
    (cmds)
      local commands; commands=(
        'admin:open this repo'\''s Admin panel a web browser'
        'browse:open this repo in a web browser'
        'clone:clone a repo'
        'config:automatically set configuration info, or pass args to specify'
        'create:create a new, empty GitHub repository'
        'create-from-local:create a new GitHub repository from the current local repository'
        'fetch:fetch from a remote to a local branch'
        'fetch_all:fetch all refs from a user'
        'fork:forks a GitHub repository'
        'home:open this repo'\''s master branch in a web browser'
        'ignore:ignore a SHA'
        'info:info about this project'
        'issues:project issues tools'
        'network:project network tools'
        'open:open the given user/project in a web browser'
        'pull:pull from a remote'
        'pull-request:generate the text for a pull request'
        'search:search GitHub for the given repository name'
        'track:track another user'\''s repository'
      )
      _describe -t commands 'command' commands && ret=0
    ;;
    (args)
      curcontext="${curcontext%:*:*}:github-cmd-$words[1]:"
      case $words[1] in
        (admin|fetch|fetch_all|home|info)
          _message 'no more arguments' && ret=0
        ;;
        (browse)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (clone)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (config)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (create)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (create-from-local)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (fork)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (home)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (ignore)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (issues)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (network)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (open)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (pull)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (pull-request)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (search)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
        (track)
          # TODO Not implemented
          _message "${words[1]} command argument" && ret=0
        ;;
      esac
    ;;
  esac

  return ret
}

_github "$@"
