Add git clone support to sandbox create
Partially address #13 by adding the `--git <repo>` option to `sandbox create`. This enables the quick cloning of a remote repository instead of doing the tedious dance of creating a sandbox, cloning the remote repo, deleting the sandbox repo them moving the `.git` directory before doing a `git reset --hard HEAD`. Additionally, improve the error messages for all `sandbox` commands, clean up the completions a little, and use a consistent style in the scripts.
This commit is contained in:
@@ -1,46 +1,42 @@
|
||||
#compdef sandbox
|
||||
|
||||
__get_sandboxes() {
|
||||
/bin/ls $SANDBOX_ROOT 2> /dev/null
|
||||
}
|
||||
|
||||
__sandboxes() {
|
||||
local -a sandboxes
|
||||
sandboxes=(${(fo)"$(__get_sandboxes)"})
|
||||
sandboxes=(${(fo)"$(ls $SANDBOX_ROOT 2> /dev/null)"})
|
||||
_describe 'in' sandboxes
|
||||
}
|
||||
|
||||
_sandbox_cmds() {
|
||||
local commands; commands=(
|
||||
'create:Create a new sandbox'
|
||||
'rename:Rename an existing sandbox'
|
||||
'destroy:Destroy an existing sandbox'
|
||||
'list:Show all existing sandboxes'
|
||||
'enable:Enable an existing sandbox'
|
||||
'disable:Disable the current sandbox'
|
||||
)
|
||||
_describe -t commands 'sandbox command' commands "$@"
|
||||
}
|
||||
|
||||
_sandbox() {
|
||||
local context curcontext="$curcontext" state line
|
||||
typeset -A opt_args
|
||||
|
||||
_arguments -C \
|
||||
'1: :_sandbox_cmds' \
|
||||
'*::arg:->args'
|
||||
'1: :->cmd' \
|
||||
'*:: :->args'
|
||||
|
||||
case $state in
|
||||
(cmd)
|
||||
local commands; commands=(
|
||||
'create:Create a new sandbox'
|
||||
'rename:Rename an existing sandbox'
|
||||
'destroy:Destroy an existing sandbox'
|
||||
'list:Show all existing sandboxes'
|
||||
'enable:Enable an existing sandbox'
|
||||
'disable:Disable the current sandbox'
|
||||
)
|
||||
_describe -t commands 'sandbox command' commands "$@"
|
||||
;;
|
||||
|
||||
(args)
|
||||
curcontext="${curcontext%:*:*}:sandbox-cmd-$words[1]:"
|
||||
case $line[1] in
|
||||
(create|list|disable)
|
||||
(create)
|
||||
_arguments -C '--git[repository to clone]: :'
|
||||
;;
|
||||
(enable|destroy)
|
||||
(rename|enable|destroy)
|
||||
_arguments -C '1:: :__sandboxes'
|
||||
;;
|
||||
(rename)
|
||||
_arguments -C '1:: :__sandboxes'
|
||||
(list|disable)
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user