Generate zsh completion script
This commit is contained in:
parent
1064e1e464
commit
296d9bd2a3
@ -1,3 +1,4 @@
|
||||
|
||||
#compdef _vagrant vagrant
|
||||
|
||||
# ZSH completion for Vagrant
|
||||
@ -9,25 +10,30 @@
|
||||
# For development reload the function after making changes
|
||||
# unfunction _vagrant && autoload -U _vagrant
|
||||
|
||||
|
||||
__box_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant box list | awk '{print $1}' )
|
||||
}
|
||||
|
||||
|
||||
__plugin_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant plugin list | awk '{print $1}')
|
||||
}
|
||||
|
||||
|
||||
function _vagrant () {
|
||||
|
||||
local -a sub_commands && sub_commands=(
|
||||
'box:manages everything related to Vagrant Cloud'
|
||||
'box:manages boxes: installation, removal, etc.'
|
||||
'cloud:manages everything related to Vagrant Cloud'
|
||||
'destroy:stops and deletes all traces of the vagrant machine'
|
||||
'global-status:outputs status Vagrant environments for this user'
|
||||
'halt:stops the vagrant machine'
|
||||
'help:shows the help for a subcommand'
|
||||
'init:initializes a new Vagrant environment by creating a Vagrantfile'
|
||||
'login:'
|
||||
'package:packages a running vagrant environment into a box'
|
||||
'plugin:manages plugins: install, uninstall, update, etc.'
|
||||
'port:displays information about guest port mappings'
|
||||
@ -37,7 +43,7 @@ function _vagrant () {
|
||||
'rdp:connects to machine via RDP'
|
||||
'reload:restarts vagrant machine, loads new Vagrantfile configuration'
|
||||
'resume:resume a suspended vagrant machine'
|
||||
'snapshot:manages snapshots; saving, restoring, etc.'
|
||||
'snapshot:manages snapshots: saving, restoring, etc.'
|
||||
'ssh:connects to machine via SSH'
|
||||
'ssh-config:outputs OpenSSH valid configuration to connect to the machine'
|
||||
'status:outputs status of the vagrant machine'
|
||||
@ -48,407 +54,683 @@ function _vagrant () {
|
||||
'version:prints current and latest Vagrant version'
|
||||
'winrm:executes commands on a machine via WinRM'
|
||||
'winrm-config:outputs WinRM configuration to connect to the machine'
|
||||
)
|
||||
)
|
||||
|
||||
local -a _box_arguments && _box_arguments=(
|
||||
'add:NAME URI Add a box to the system'
|
||||
'help:COMMAND Describe subcommands or one specific subcommand'
|
||||
'list:Lists all installed boxes'
|
||||
'outdated:Checks if there is a new version available for the box'
|
||||
'prune:Removes boxes'
|
||||
'remove:NAME Remove a box from the system'
|
||||
'repackage:NAME Repackage an installed box into a `.box` file.'
|
||||
'update:Updates the box, if there any updates available'
|
||||
)
|
||||
|
||||
local -a _snapshot_arguments && _snapshot_arguments=(
|
||||
'delete:Delete a snapshot taken previously with snapshot save'
|
||||
'list:List all snapshots taken for a machine'
|
||||
'pop:Restore state that was pushed onto the snapshot stack'
|
||||
'push:Take a snapshot of the current state of the machine and push it onto the stack of states'
|
||||
'restore:Restore a snapshot taken previously with snapshot save.'
|
||||
'save:Take a snapshot of the current state of the machine'
|
||||
)
|
||||
|
||||
local -a _plugin_arguments && _plugin_arguments=(
|
||||
'expunge:Expunge a plugin'
|
||||
'install:Install a plugin'
|
||||
'license:Install the license for a plugin'
|
||||
'list:List plugins'
|
||||
'repair:Repair a broken plugin'
|
||||
'uninstall:Uninstall a plugin'
|
||||
'update:Lookup new version of plugins and install'
|
||||
)
|
||||
|
||||
local -a common_arguments && common_arguments=(
|
||||
local -a cloud_arguments && cloud_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamp]'
|
||||
'--no-tty=[Enable non-interactive output]'
|
||||
'--help=[Print help message]'
|
||||
)
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a destroy_arguments && destroy_arguments=(
|
||||
'--force=[Destroy without confirmation]'
|
||||
'--(no-)parallel=[Enable or disable parallelism if provider supports it]'
|
||||
)
|
||||
local -a destroy_arguments && destroy_arguments=(
|
||||
'--(no-)parallel=[Enable or disable parallelism if provider supports it (automatically enables force)]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a global_status_arguments && global_status_arguments=(
|
||||
'--prune=[Prune invalid entries]'
|
||||
)
|
||||
local -a global_status_arguments && global_status_arguments=(
|
||||
'--prune=[Prune invalid entries.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a halt_arguments && halt_arguments=(
|
||||
'--force=[Force shut down (equivalent of pulling power)]'
|
||||
)
|
||||
local -a halt_arguments && halt_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a init_arguments && init_arguments=(
|
||||
'--box-version VERSION=[Version of the box to add]'
|
||||
'--force=[Overwrite existing Vagrantfile]'
|
||||
'--minimal=[Use minimal Vagrantfile template (no help comments). Ignored with --template]'
|
||||
'--output FILE=[Output path for the box. "-" for stdout]'
|
||||
'--template FILE=[Path to custom Vagrantfile template]'
|
||||
)
|
||||
local -a help_arguments && help_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a package_arguments && package_arguments=(
|
||||
'--base NAME=[Name of a VM in VirtualBox to package as a base box (VirtualBox Only)]'
|
||||
'--output NAME=[Name of the file to output]'
|
||||
'--include FILE,FILE=[Comma separated additional files to package with the box]'
|
||||
'--vagrantfile FILE=[Vagrantfile to package with the box]'
|
||||
)
|
||||
local -a init_arguments && init_arguments=(
|
||||
'--box-version=[Version of the box to add]'
|
||||
'--output=[Output path for the box. _ for stdout]'
|
||||
'--template=[Path to custom Vagrantfile template]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a port_arguments && port_arguments=(
|
||||
'--guest=[NOutput the host port that maps to the given guest port]'
|
||||
)
|
||||
local -a login_arguments && login_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a powershell_arguments && powershell_arguments=(
|
||||
'--command COMMAND=[Execute a powershell command directly]'
|
||||
'--elevated=[Execute a powershell command with elevated permissions]'
|
||||
)
|
||||
local -a package_arguments && package_arguments=(
|
||||
'--base=[Name of a VM in VirtualBox to package as a base box (VirtualBox Only)]'
|
||||
'--output=[Name of the file to output]'
|
||||
'--include=[Comma separated additional files to package with the box]'
|
||||
'--vagrantfile=[Vagrantfile to package with the box]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a provision_arguments && provision_arguments=(
|
||||
'--provision-with x,y,z=[Enable only certain provisioners, by type or by name]'
|
||||
)
|
||||
local -a port_arguments && port_arguments=(
|
||||
'--guest=[Output the host port that maps to the given guest port]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a reload_arguments && reload_arguments=(
|
||||
local -a powershell_arguments && powershell_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a provision_arguments && provision_arguments=(
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a push_arguments && push_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a rdp_arguments && rdp_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a reload_arguments && reload_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with x,y,z=[Enable only certain provisioners, by type or by name]'
|
||||
'--force=[Force shut down (equivalent of pulling power)]'
|
||||
)
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a resume_arguments && resume_arguments=(
|
||||
local -a resume_arguments && resume_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with x,y,z=[Enable only certain provisioners, by type or by name]'
|
||||
)
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a ssh_arguments && ssh_arguments=(
|
||||
'--command=[Execute an SSH command directly]'
|
||||
'--plain=[Plain mode, leaves authentication up to user]'
|
||||
'--(no-)tty=[Enables tty when executing an ssh command (defaults to true)]'
|
||||
)
|
||||
local -a ssh_arguments && ssh_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a ssh_config_arguments && ssh_config_arguments=(
|
||||
'--host NAME=[Name the host or the config]'
|
||||
)
|
||||
local -a ssh_config_arguments && ssh_config_arguments=(
|
||||
'--host=[Name the host for the config]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a suspend_arguments && suspend_arguments=(
|
||||
'--all-global=[Suspend all running vms globally]'
|
||||
)
|
||||
local -a status_arguments && status_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a up_arguments && up_arguments=(
|
||||
local -a suspend_arguments && suspend_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a up_arguments && up_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with x,y,z=[Enable only certain provisioners, by type or by name]'
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--(no-)destroy-on-error=[Destroy machine if any fatal error happens (default to true)]'
|
||||
'--(no-)parallel=[Enable or disable parallelism if provider supports it]'
|
||||
'--provider=[Back the machine with a specific provider]'
|
||||
'--(no-)install-provider=[If possible, install the provider if it is not installed]'
|
||||
)
|
||||
'--(no-)install-provider=[If possible, install the provider if it isnt installed]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a upload_arguments && upload_arguments=(
|
||||
'--temporary=[Upload source to temporary directory]'
|
||||
'--compress=[Use gzip compression for upload]'
|
||||
'--compression-type\=TYPE=[Type of compression to use (tgz, zip)]'
|
||||
)
|
||||
local -a upload_arguments && upload_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a validate_arguments && validate_arguments=(
|
||||
'--ignore-provider=[Ignores provider config options]'
|
||||
)
|
||||
local -a validate_arguments && validate_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a winrm_arguments && winrm_arguments=(
|
||||
'--command COMMAND=[Execute a WinRM command directly]'
|
||||
'--elevated=[Run with elevated credentials]'
|
||||
'--shell SHELL=[Use specified shell (powershell, cmd)]'
|
||||
)
|
||||
local -a version_arguments && version_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a winrm_config_arguments && winrm_config_arguments=(
|
||||
'--host NAME=[Name the host for the config]'
|
||||
)
|
||||
local -a winrm_arguments && winrm_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
_arguments -C \
|
||||
':command:->command' \
|
||||
'*::options:->options'
|
||||
local -a winrm_config_arguments && winrm_config_arguments=(
|
||||
'--host=[Name the host for the config]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
case $state in
|
||||
command)
|
||||
_describe -t commands 'command' sub_commands ;;
|
||||
options)
|
||||
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
box)
|
||||
__vagrant-box ;;
|
||||
cloud)
|
||||
_arguments -s -S : $common_arguments ;;
|
||||
_arguments -s -S : $cloud_arguments ;;
|
||||
destroy)
|
||||
_arguments -s -S : $destroy_arguments $common_arguments ;;
|
||||
_arguments -s -S : $destroy_arguments ;;
|
||||
global-status)
|
||||
_arguments -s -S : $global_status_arguments $common_arguments ;;
|
||||
_arguments -s -S : $global_status_arguments ;;
|
||||
halt)
|
||||
_arguments -s -S : $halt_arguments $common_arguments ;;
|
||||
_arguments -s -S : $halt_arguments ;;
|
||||
help)
|
||||
_arguments -s -S : $help_arguments ;;
|
||||
init)
|
||||
_arguments -s -S : $init_arguments $common_arguments ;;
|
||||
_arguments -s -S : $init_arguments ;;
|
||||
login)
|
||||
_arguments -s -S : $login_arguments ;;
|
||||
package)
|
||||
_arguments -s -S : $package_arguments $common_arguments ;;
|
||||
_arguments -s -S : $package_arguments ;;
|
||||
plugin)
|
||||
__vagrant-plugin ;;
|
||||
port)
|
||||
_arguments -s -S : $port_arguments $common_arguments ;;
|
||||
_arguments -s -S : $port_arguments ;;
|
||||
powershell)
|
||||
_arguments -s -S : $powershell_arguments $common_arguments ;;
|
||||
_arguments -s -S : $powershell_arguments ;;
|
||||
provision)
|
||||
_arguments -s -S : $provision_arguments $common_arguments ;;
|
||||
_arguments -s -S : $provision_arguments ;;
|
||||
push)
|
||||
_arguments -s -S : $common_arguments ;;
|
||||
_arguments -s -S : $push_arguments ;;
|
||||
rdp)
|
||||
_arguments -s -S : $common_arguments ;;
|
||||
_arguments -s -S : $rdp_arguments ;;
|
||||
reload)
|
||||
_arguments -s -S : $reload_arguments $common_arguments ;;
|
||||
_arguments -s -S : $reload_arguments ;;
|
||||
resume)
|
||||
_arguments -s -S : $resume_arguments $common_arguments ;;
|
||||
_arguments -s -S : $resume_arguments ;;
|
||||
snapshot)
|
||||
__vagrant-snapshot ;;
|
||||
ssh)
|
||||
_arguments -s -S : $ssh_arguments $common_arguments ;;
|
||||
_arguments -s -S : $ssh_arguments ;;
|
||||
ssh-config)
|
||||
_arguments -s -S : $ssh_config_arguments $common_arguments ;;
|
||||
_arguments -s -S : $ssh_config_arguments ;;
|
||||
status)
|
||||
_arguments -s -S : $common_arguments ;;
|
||||
_arguments -s -S : $status_arguments ;;
|
||||
suspend)
|
||||
_arguments -s -S : $suspend_arguments $common_arguments ;;
|
||||
_arguments -s -S : $suspend_arguments ;;
|
||||
up)
|
||||
_arguments -s -S : $up_arguments $common_arguments ;;
|
||||
_arguments -s -S : $up_arguments ;;
|
||||
upload)
|
||||
_arguments -s -S : $upload_arguments $common_arguments ;;
|
||||
_arguments -s -S : $upload_arguments ;;
|
||||
validate)
|
||||
_arguments -s -S : $validate_arguments $common_arguments ;;
|
||||
_arguments -s -S : $validate_arguments ;;
|
||||
version)
|
||||
_arguments -s -S : $version_arguments ;;
|
||||
winrm)
|
||||
_arguments -s -S : $winrm_arguments $common_arguments ;;
|
||||
_arguments -s -S : $winrm_arguments ;;
|
||||
winrm-config)
|
||||
_arguments -s -S : $winrm_config_arguments $common_arguments ;;
|
||||
esac
|
||||
_arguments -s -S : $winrm_config_arguments ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
__vagrant-box ()
|
||||
{
|
||||
local curcontext="$curcontext" state line
|
||||
typeset -A opt_args
|
||||
function __vagrant-box () {
|
||||
|
||||
local -a box_common_arguments && box_common_arguments=(
|
||||
'--help[Print help message]'
|
||||
)
|
||||
local -a sub_commands && sub_commands=(
|
||||
'add:add'
|
||||
'list:list'
|
||||
'outdated:outdated'
|
||||
'prune:prune'
|
||||
'remove:remove'
|
||||
'repackage:repackage'
|
||||
'update:update'
|
||||
)
|
||||
|
||||
local -a box_ca_arguments && box_ca_arguments=(
|
||||
'--cacert FILE[CA certificate for SSL download]'
|
||||
'--capath DIR[CA certificate directory for SSL download]'
|
||||
'--cert FILE[A client SSL cert, if needed]'
|
||||
'--insecure[Do not validate SSL certificates]'
|
||||
)
|
||||
local -a add_arguments && add_arguments=(
|
||||
'--insecure=[Do not validate SSL certificates]'
|
||||
'--cacert=[CA certificate for SSL download]'
|
||||
'--capath=[CA certificate directory for SSL download]'
|
||||
'--cert=[A client SSL cert, if needed]'
|
||||
'--location-trusted=[Trust Location header from HTTP redirects and use the same credentials for subsequent urls as for the initial one]'
|
||||
'--provider=[Provider the box should satisfy]'
|
||||
'--box-version=[Constrain version of the added box]'
|
||||
'--checksum=[Checksum for the box]'
|
||||
'--checksum-type=[Checksum type (md5, sha1, sha256)]'
|
||||
'--name=[Name of the box]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a box_add_arguments && box_add_arguments=(
|
||||
'--clean[Clean any temporary download files]'
|
||||
'--force[Overwrite an existing box if it exists]'
|
||||
'--location-trustedTrust["Location" header from HTTP redirects and use the same credentials for subsequent urls as for the initial one]'
|
||||
'--provider PROVIDER[Provider the box should satisfy]'
|
||||
'--box-version VERSION[Constrain version of the added box]'
|
||||
'--checksum CHECKSUM[Checksum for the box]'
|
||||
'--checksum-type TYPE[Checksum type (md5, sha1, sha256)]'
|
||||
'--name BOX[Name of the box]'
|
||||
)
|
||||
local -a list_arguments && list_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a box_list_arguments && box_list_arguments=(
|
||||
'--box-info[Displays additional information about the boxes]'
|
||||
)
|
||||
local -a outdated_arguments && outdated_arguments=(
|
||||
'--global=[Check all boxes installed]'
|
||||
'--insecure=[Do not validate SSL certificates]'
|
||||
'--cacert=[CA certificate for SSL download]'
|
||||
'--capath=[CA certificate directory for SSL download]'
|
||||
'--cert=[A client SSL cert, if needed]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a box_outdated_arguments && box_outdated_arguments=(
|
||||
'--global[Check all boxes installed]'
|
||||
'--force[Force checks for latest box updates]'
|
||||
)
|
||||
local -a prune_arguments && prune_arguments=(
|
||||
'--name=[The specific box name to check for outdated versions.]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a box_prune_arguments && box_prune_arguments=(
|
||||
'--provider PROVIDER[The specific provider type for the boxes to destroy]'
|
||||
'--dry-run[Only print the boxes that would be removed]'
|
||||
'--name NAME[The specific box name to check for outdated versions]'
|
||||
'--force[Destroy without confirmation even when box is in use]'
|
||||
'--keep-active-boxes[When combined with `--force`, will keep boxes still actively in use]'
|
||||
)
|
||||
local -a remove_arguments && remove_arguments=(
|
||||
'--provider=[The specific provider type for the box to remove]'
|
||||
'--box-version=[The specific version of the box to remove]'
|
||||
'--all=[Remove all available versions of the box]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a box_remove_arguments && box_remove_arguments=(
|
||||
'--force[Remove without confirmation]'
|
||||
'--provider PROVIDER[The specific provider type for the boxes to destroy]'
|
||||
'--box-version VERSION[The specific version of the box to remove]'
|
||||
'--all[Remove all available versions of the box]'
|
||||
)
|
||||
local -a repackage_arguments && repackage_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a box_update_arguments && box_update_arguments=(
|
||||
'--box BOX[Update a specific box]'
|
||||
'--force[Overwrite an existing box if it exists]'
|
||||
'--provider PROVIDER[The specific provider type for the boxes to destroy]'
|
||||
)
|
||||
local -a update_arguments && update_arguments=(
|
||||
'--box=[__box flag.]'
|
||||
'--box=[Update a specific box]'
|
||||
'--provider=[Update box with specific provider]'
|
||||
'--insecure=[Do not validate SSL certificates]'
|
||||
'--cacert=[CA certificate for SSL download]'
|
||||
'--capath=[CA certificate directory for SSL download]'
|
||||
'--cert=[A client SSL cert, if needed]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
_arguments -C \
|
||||
':command:->command' \
|
||||
'*::options:->options'
|
||||
|
||||
case $state in
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' _box_arguments
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
add)
|
||||
_arguments -s -S : $box_add_arguments $box_ca_arguments $box_common_arguments ;;
|
||||
_arguments -s -S : $add_arguments ;;
|
||||
list)
|
||||
_arguments -s -S : $box_list_arguments $box_common_arguments ;;
|
||||
_arguments -s -S : $list_arguments ;;
|
||||
outdated)
|
||||
_arguments -s -S : $box_outdated_arguments $box_ca_arguments $box_common_arguments ;;
|
||||
_arguments -s -S : $outdated_arguments ;;
|
||||
prune)
|
||||
_arguments -s -S : $box_prune_arguments $box_common_arguments ;;
|
||||
_arguments -s -S : $prune_arguments ;;
|
||||
remove)
|
||||
_arguments -s -S : $box_remove_arguments $box_common_arguments ':feature:__box_list' ;;
|
||||
_arguments -s -S : $remove_arguments ':feature:__box_list' ;;
|
||||
repackage)
|
||||
_arguments -s -S : $box_common_arguments ':feature:__box_list' ;;
|
||||
_arguments -s -S : $repackage_arguments ':feature:__box_list' ;;
|
||||
update)
|
||||
_arguments -s -S : $box_update_arguments $box_ca_arguments $box_common_arguments ':feature:__box_list';;
|
||||
esac
|
||||
_arguments -s -S : $update_arguments ':feature:__box_list' ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
__vagrant-snapshot ()
|
||||
{
|
||||
local curcontext="$curcontext" state line
|
||||
typeset -A opt_args
|
||||
function __vagrant-snapshot () {
|
||||
|
||||
local -a snapshot_common_arguments && snapshot_common_arguments=(
|
||||
'--help[Print help message]'
|
||||
)
|
||||
local -a sub_commands && sub_commands=(
|
||||
'delete:delete'
|
||||
'list:list'
|
||||
'pop:pop'
|
||||
'push:push'
|
||||
'restore:restore'
|
||||
'save:save'
|
||||
)
|
||||
|
||||
local -a snapshot_provision_arguments && snapshot_provision_arguments=(
|
||||
local -a delete_arguments && delete_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a list_arguments && list_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a pop_arguments && pop_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with x,y,z=[Enable only certain provisioners, by type or by name]'
|
||||
)
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--no-delete=[Dont delete the snapshot after the restore]'
|
||||
'--no-start=[Dont start the snapshot after the restore]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a snapshot_start_argument && snapshot_start_argument=(
|
||||
'--no-start=[Do not start the snapshot after the restore]'
|
||||
)
|
||||
local -a push_arguments && push_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a snapshot_pop_arguments && snapshot_pop_arguments=(
|
||||
'--no-delete=[Do not delete the snapshot after the restore]'
|
||||
)
|
||||
local -a restore_arguments && restore_arguments=(
|
||||
'--(no-)provision=[Enable or disable provisioning]'
|
||||
'--provision-with=[Enable only certain provisioners, by type or by name.]'
|
||||
'--no-start=[Dont start the snapshot after the restore]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a snapshot_force_arguments && snapshot_force_arguments=(
|
||||
'--force=[Replace snapshot without confirmation]'
|
||||
)
|
||||
local -a save_arguments && save_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
_arguments -C \
|
||||
':command:->command' \
|
||||
'*::options:->options'
|
||||
|
||||
case $state in
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' _snapshot_arguments
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
delete)
|
||||
_arguments -s -S : $snapshot_common_arguments ;;
|
||||
_arguments -s -S : $delete_arguments ;;
|
||||
list)
|
||||
_arguments -s -S : $snapshot_common_arguments ;;
|
||||
_arguments -s -S : $list_arguments ;;
|
||||
pop)
|
||||
_arguments -s -S : $snapshot_pop_arguments $snapshot_start_argument $snapshot_provision_arguments $snapshot_common_arguments ;;
|
||||
_arguments -s -S : $pop_arguments ;;
|
||||
push)
|
||||
_arguments -s -S : $snapshot_common_arguments ;;
|
||||
_arguments -s -S : $push_arguments ;;
|
||||
restore)
|
||||
_arguments -s -S : $snapshot_provision_arguments $snapshot_start_argument $snapshot_common_arguments ;;
|
||||
_arguments -s -S : $restore_arguments ;;
|
||||
save)
|
||||
_arguments -s -S : $snapshot_force_arguments $snapshot_common_arguments ;;
|
||||
esac
|
||||
_arguments -s -S : $save_arguments ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
__vagrant-plugin ()
|
||||
{
|
||||
local curcontext="$curcontext" state line
|
||||
typeset -A opt_args
|
||||
function __vagrant-plugin () {
|
||||
|
||||
local -a plugin_common_arguments && plugin_common_arguments=(
|
||||
'--help[Print help message]'
|
||||
)
|
||||
local -a sub_commands && sub_commands=(
|
||||
'expunge:expunge'
|
||||
'install:install'
|
||||
'license:license'
|
||||
'list:list'
|
||||
'repair:repair'
|
||||
'uninstall:uninstall'
|
||||
'update:update'
|
||||
)
|
||||
|
||||
local -a plugin_local_arguments && plugin_local_arguments=(
|
||||
'--local[Remove plugin from local project]'
|
||||
)
|
||||
local -a expunge_arguments && expunge_arguments=(
|
||||
'--force=[Do not prompt for confirmation]'
|
||||
'--local=[Include plugins from local project for expunge]'
|
||||
'--local-only=[Only expunge local project plugins]'
|
||||
'--global-only=[Only expunge global plugins]'
|
||||
'--reinstall=[Reinstall current plugins after expunge]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a plugin_install_arguments && plugin_install_arguments=(
|
||||
'--entry-point NAME[The name of the entry point file for loading the plugin]'
|
||||
'--plugin-clean-sources[Remove all plugin sources defined so far (including defaults)]'
|
||||
'--plugin-source PLUGIN_SOURCE[Add a RubyGems repository source]'
|
||||
'--plugin-version PLUGIN_VERSION[Install a specific version of the plugin]'
|
||||
'--local[Install plugin for local project only]'
|
||||
'--verbose[Enable verbose output for plugin installation]'
|
||||
)
|
||||
local -a install_arguments && install_arguments=(
|
||||
'--entry-point=[The name of the entry point file for loading the plugin.]'
|
||||
'--plugin-clean-sources=[Remove all plugin sources defined so far (including defaults)]'
|
||||
'--plugin-source=[__plugin_source PLUGIN_SOURCE]'
|
||||
'--plugin-version=[__plugin_version PLUGIN_VERSION]'
|
||||
'--local=[Install plugin for local project only]'
|
||||
'--verbose=[Enable verbose output for plugin installation]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a plugin_expunge_arguments && plugin_expunge_arguments=(
|
||||
'--force[Do not prompt for confirmation]'
|
||||
'--local[Include plugins from local project for expunge]'
|
||||
'--local-only[Only expunge local project plugins]'
|
||||
'--global-only[Only expunge global plugins]'
|
||||
'--reinstall[Reinstall current plugins after expunge]'
|
||||
)
|
||||
local -a license_arguments && license_arguments=(
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
_arguments -C \
|
||||
':command:->command' \
|
||||
'*::options:->options'
|
||||
local -a list_arguments && list_arguments=(
|
||||
'--local=[Include local project plugins]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
case $state in
|
||||
local -a repair_arguments && repair_arguments=(
|
||||
'--local=[Repair plugins in local project]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a uninstall_arguments && uninstall_arguments=(
|
||||
'--local=[Remove plugin from local project]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
local -a update_arguments && update_arguments=(
|
||||
'--local=[Update plugin in local project]'
|
||||
'--(no-)color=[Enable or disable color output]'
|
||||
'--machine-readable=[Enable machine readable output]'
|
||||
'--debug=[Enable debug output]'
|
||||
'--timestamp=[Enable timestamps on log output]'
|
||||
'--debug-timestamp=[Enable debug output with timestamps]'
|
||||
'--no-tty=[Enable non_interactive output]'
|
||||
)
|
||||
|
||||
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' _plugin_arguments
|
||||
_describe -t commands 'command' sub_commands
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
install)
|
||||
_arguments -s -S : $plugin_install_arguments $plugin_common_arguments ;;
|
||||
expunge)
|
||||
_arguments -s -S : $plugin_expunge_arguments $plugin_common_arguments ;;
|
||||
_arguments -s -S : $expunge_arguments ;;
|
||||
install)
|
||||
_arguments -s -S : $install_arguments ;;
|
||||
license)
|
||||
_arguments -s -S : $plugin_common_arguments ;;
|
||||
_arguments -s -S : $license_arguments ;;
|
||||
list)
|
||||
_arguments -s -S : $plugin_common_arguments ;;
|
||||
_arguments -s -S : $list_arguments ;;
|
||||
repair)
|
||||
_arguments -s -S : $plugin_local_arguments $plugin_common_arguments ':feature:__plugin_list' ;;
|
||||
_arguments -s -S : $repair_arguments ':feature:__plugin_list' ;;
|
||||
uninstall)
|
||||
_arguments -s -S : $plugin_local_arguments $plugin_common_arguments ':feature:__plugin_list' ;;
|
||||
_arguments -s -S : $uninstall_arguments ':feature:__plugin_list' ;;
|
||||
update)
|
||||
_arguments -s -S : $plugin_local_arguments $plugin_common_arguments ':feature:__plugin_list' ;;
|
||||
esac
|
||||
_arguments -s -S : $update_arguments ':feature:__plugin_list' ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
}
|
||||
166
contrib/zsh/generate_zsh_completion.rb
Normal file
166
contrib/zsh/generate_zsh_completion.rb
Normal file
@ -0,0 +1,166 @@
|
||||
require 'open3'
|
||||
|
||||
HEAD = """
|
||||
#compdef _vagrant vagrant
|
||||
|
||||
# ZSH completion for Vagrant
|
||||
#
|
||||
# To use this completion add this to ~/.zshrc
|
||||
# fpath=(/path/to/this/dir $fpath)
|
||||
# compinit
|
||||
#
|
||||
# For development reload the function after making changes
|
||||
# unfunction _vagrant && autoload -U _vagrant
|
||||
"""
|
||||
|
||||
BOX_LIST_FUNCTION = """
|
||||
__box_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant box list | awk '{print $1}' )
|
||||
}
|
||||
"""
|
||||
|
||||
PLUGIN_LIST_FUNCTION = """
|
||||
__plugin_list ()
|
||||
{
|
||||
_wanted application expl 'command' compadd $(command vagrant plugin list | awk '{print $1}')
|
||||
}
|
||||
"""
|
||||
|
||||
ADD_FEATURE_FLAGS = ["remove", "repackage", "update", "repair", "uninstall"]
|
||||
VAGRANT_COMMAND = "vagrant"
|
||||
|
||||
FLAG_REGEX = /--(\S)*/
|
||||
CMDS_REGEX = /^(\s){1,}(\w)(\S)*/
|
||||
|
||||
def make_string_script_safe(s)
|
||||
s.gsub("[","(").gsub("]",")").gsub("-","_").gsub("'", "")
|
||||
end
|
||||
|
||||
def remove_square_brakets(s)
|
||||
s.gsub("[","(").gsub("]",")")
|
||||
end
|
||||
|
||||
def format_flags(group_name, flags)
|
||||
group_name = make_string_script_safe(group_name)
|
||||
opts_str = "local -a #{group_name} && #{group_name}=(\n"
|
||||
flags.each do |flag, desc|
|
||||
opts_str = opts_str + " '#{remove_square_brakets(flag)}=[#{make_string_script_safe(desc)}]'\n"
|
||||
end
|
||||
opts_str + ")"
|
||||
end
|
||||
|
||||
def format_subcommand(group_name, cmds)
|
||||
opts_str = "local -a #{group_name} && #{group_name}=(\n"
|
||||
cmds.each do |cmd, desc|
|
||||
opts_str = opts_str + " '#{cmd}:#{desc}'\n"
|
||||
end
|
||||
opts_str + ")"
|
||||
end
|
||||
|
||||
def format_case(group_name, cmds, cmd_list, feature_string)
|
||||
case_str = """case $state in
|
||||
(command)
|
||||
_describe -t commands 'command' #{group_name}
|
||||
return
|
||||
;;
|
||||
|
||||
(options)
|
||||
case $line[1] in
|
||||
"""
|
||||
|
||||
cmds.each do |cmd, desc|
|
||||
if cmd_list.include?(cmd)
|
||||
case_append = """ #{cmd})
|
||||
_arguments -s -S : $#{make_string_script_safe(cmd)}_arguments #{feature_string if ADD_FEATURE_FLAGS.include?(cmd)} ;;
|
||||
"""
|
||||
else
|
||||
case_append = """ #{cmd})
|
||||
__vagrant-#{cmd} ;;
|
||||
"""
|
||||
end
|
||||
case_str = case_str + case_append
|
||||
end
|
||||
|
||||
case_str = case_str + """esac
|
||||
;;
|
||||
esac
|
||||
"""
|
||||
end
|
||||
|
||||
def extract_flags(top_level_commands)
|
||||
flags = top_level_commands.map { |c| [c.match(FLAG_REGEX)[0], c.split(" ")[-1].strip] if c.strip.start_with?("--") }.compact
|
||||
end
|
||||
|
||||
def extract_subcommand(top_level_commands)
|
||||
cmds = top_level_commands.map { |c| [c.match(CMDS_REGEX)[0].strip, c.split(" ")[-1].strip] if c.match(CMDS_REGEX) }.compact
|
||||
end
|
||||
|
||||
def get_top_level_commands(root_command, cmd_list)
|
||||
stdout, stderr, status = Open3.capture3("vagrant #{root_command} -h")
|
||||
top_level_commands = stdout.split("\n")
|
||||
|
||||
root_subcommand = extract_subcommand(top_level_commands)
|
||||
commands = format_subcommand("sub_commands", root_subcommand)
|
||||
if root_command == "box"
|
||||
feature_string = "':feature:__box_list'"
|
||||
elsif root_command == "plugin"
|
||||
feature_string = "':feature:__plugin_list'"
|
||||
else
|
||||
feature_string = ""
|
||||
end
|
||||
case_string = format_case("sub_commands", root_subcommand, cmd_list, feature_string)
|
||||
|
||||
flags_def = ""
|
||||
root_subcommand.each do |cmd, desc|
|
||||
next if !cmd_list.include?(cmd)
|
||||
stdout, stderr, status = Open3.capture3("vagrant #{root_command} #{cmd} -h")
|
||||
cmd_help = stdout.split("\n")
|
||||
flags_def = flags_def + format_flags("#{cmd}_arguments", extract_flags(cmd_help)) + "\n\n"
|
||||
end
|
||||
|
||||
return commands, flags_def, case_string
|
||||
end
|
||||
|
||||
def format_script(root_command, subcommands, funciton_name)
|
||||
top_level_commands, top_level_args, state_case = get_top_level_commands(root_command, subcommands)
|
||||
|
||||
script = """
|
||||
function #{funciton_name} () {
|
||||
|
||||
#{top_level_commands}
|
||||
|
||||
#{top_level_args}
|
||||
|
||||
_arguments -C ':command:->command' '*::options:->options'
|
||||
|
||||
#{state_case}
|
||||
}
|
||||
"""
|
||||
end
|
||||
|
||||
def generate_script
|
||||
subcommand_list = {
|
||||
"" => ["cloud", "destroy", "global-status", "halt", "help", "login", "init", "package", "port", "powershell", "provision", "push", "rdp", "reload", "resume", "ssh", "ssh-config", "status", "suspend", "up", "upload", "validate", "version", "winrm", "winrm-config"],
|
||||
"box" => ["add", "list", "outdated", "prune", "remove", "repackage", "update"],
|
||||
"snapshot" => ["delete", "list", "pop", "push", "restore", "save"],
|
||||
"plugin" => ["install", "expunge", "license", "list", "repair", "uninstall", "update"],
|
||||
}
|
||||
|
||||
script = """#{HEAD}
|
||||
#{BOX_LIST_FUNCTION}
|
||||
#{PLUGIN_LIST_FUNCTION}
|
||||
"""
|
||||
|
||||
subcommand_list.each do |cmd, opts|
|
||||
if cmd != ""
|
||||
function_name = "__vagrant-#{cmd}"
|
||||
else
|
||||
function_name = "_vagrant"
|
||||
end
|
||||
script = script + format_script(cmd, opts, function_name)
|
||||
end
|
||||
script
|
||||
end
|
||||
|
||||
puts generate_script
|
||||
Loading…
x
Reference in New Issue
Block a user