#compdef boot2docker
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for boot2docker (https://github.com/boot2docker/boot2docker-cli).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * hhatto (https://github.com/hhatto)
#
# ------------------------------------------------------------------------------


_boot2docker() {
  local context state line

  _arguments -C \
    --basevmdk'[Path to VMDK to use as base for persistent partition]:vmdk:' \
    --dhcp'[enable VirtualBox host-only network DHCP. default=true]' \
    --dhcpip'[VirtualBox host-only network DHCP server address. default=192.168.59.99]' \
    '(-s --disksize)'{-s,--disksize}'[boot2docker disk image size (in MB). default=20000.]:disksize:' \
    --dockerport'[host Docker port (forward to port 2375 in VM).]:PORT:' \
    --hostip'[VirtualBox host-only network IP address.]:IP:' \
    --iso'[path to boot2docker ISO image.]:FILE:_files' \
    --lowerip'[VirtualBox host-only network DHCP lower bound.]:IP:' \
    '(-m --memory)'{-m,--memory}'[virtual machine memory size (in MB). default=2048]' \
    --netmask'[VirtualBox host-only network mask.]' \
    --serial'[try serial console to get IP address (experimental) defalut=false]' \
    --serialfile'[path to the serial socket/pipe.]:FILE:_files' \
    --ssh'[path to SSH client utility. defalut="ssh"]:SSH:' \
    --ssh-keygen'[path to ssh-keygen utility. defalut="ssh-keygen"]:KEYGEN:' \
    --sshkey'[path to SSH key to use.]:FILE:_files' \
    --sshport'[host SSH port (forward to port 22 in VM). defalut=2022]:PORT:' \
    --upperip'[VirtualBox host-only network DHCP upper bound. defalut=192.168.59.254]:IP:' \
    --vbm'[path to VirtualBox management utility. defalut="VBoxManage"]' \
    '(-v --verbose)'{-v,--verbose}'[display verbose command invocations. defalut=false]' \
    --vm'[virtual machine name. defalut="boot2docker-vm"]' \
    '*::boot2docker commands:_boot2docker_command'
}

(( $+functions[_boot2docker_command] )) ||
_boot2docker_command() {
  local _boot2docker_cmds

  _boot2docker_cmds=(
    'init:Create a new boot2docker VM.' \
    'up:Start VM from any states.' \
    'start:[Start VM from any states.' \
    'boot:[Start VM from any states.' \
    'ssh:Login to VM via SSH.' \
    'save:Suspend VM and save state to disk.' \
    'suspend:Suspend VM and save state to disk.' \
    "down:Gracefully shutdown the VM." \
    "stop:Gracefully shutdown the VM." \
    "halt:Gracefully shutdown the VM." \
    "restart:Gracefully reboot the VM." \
    "poweroff:Forcefully power off the VM (might corrupt disk image)." \
    "reset:Forcefully power cycle the VM (might corrupt disk image)." \
    "delete:Delete boot2docker VM and its disk image." \
    "destroy:Delete boot2docker VM and its disk image." \
    "config:Show selected profile file settings." \
    "cfg:Show selected profile file settings." \
    "info:Display detailed information of VM." \
    "ip:Display the IP address of the VM's Host-only network." \
    "status:Display current state of VM." \
    "download:Download boot2docker ISO image." \
    "upgrade:Upgrade the boot2docker ISO image (if vm is running it will be stopped and started)." \
    "version:Display version information."
    )

  if (( CURRENT == 1 )); then
    _describe -t commands 'boot2docker subcommand' _boot2docker_cmds
  fi
}

_boot2docker "$@"

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et
