#23 github: rewrite using arguments (properly sets context and allow extension)

This commit is contained in:
Julien Nicoulaud 2011-08-31 21:25:56 +02:00
parent ac42847bb2
commit 307ce5aafa
1 changed files with 43 additions and 27 deletions

70
_github
View File

@ -20,32 +20,48 @@
# ------------------------------------------------------------------------------
local -a _1st_arguments
_1st_arguments=(
'browse:Open this repo in a web browser'
'clone:Clone a repo'
'config:Automatically set configuration info, or pass args to specify'
'create-from-local:Create a new GitHub repository from the current local repository'
'create:Create a new empty GitHub 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 repos master branch in a web browser'
'ignore:Ignore a SHA from github network commits'
'info:Info about this project'
'issues:Project issues tools'
'network:Project network tools - sub-commands : web [user], list, fetch, commits'
'open:Open the given user/project in a web browser'
'pull-request:Generate the text for a pull request'
'pull:Pull from a remote'
'search:Search GitHub for the given repository name'
'track:Track another users repository'
)
typeset -A opt_args
local context state line curcontext="$curcontext"
_arguments \
'*:: :->subcmds' && return 0
_github() {
local ret=1
if (( CURRENT == 1 )); then
_describe -t commands "github subcommand" _1st_arguments
return
fi
_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]:"
;;
esac
return ret
}
_github "$@"