2013-07-29 23:13:29 +04:00
#compdef machinectl
2017-11-18 20:21:19 +03:00
# SPDX-License-Identifier: LGPL-2.1+
2013-07-29 23:13:29 +04:00
2018-12-24 14:15:38 +03:00
(( $+functions[__machinectl_get_machines] )) ||
__machinectl_get_machines () {
2015-04-23 01:52:59 +03:00
machinectl --no-legend list-images | {while read -r a b; do echo $a; done;}
}
2018-12-24 14:15:38 +03:00
(( $+functions[_machinectl_machines] )) ||
_machinectl_machines() {
2015-04-23 01:52:59 +03:00
local -a _machines
2018-12-24 14:15:38 +03:00
_machines=("${(fo)$(__machinectl_get_machines)}")
2015-04-23 01:52:59 +03:00
typeset -U _machines
if [[ -n "$_machines" ]]; then
_describe 'machines' _machines
else
_message 'no machines'
fi
}
2018-12-24 14:15:38 +03:00
(( $+functions[_machinectl_commands] )) || _machinectl_commands()
2013-07-29 23:13:29 +04:00
{
local -a _machinectl_cmds
_machinectl_cmds=(
"list:List currently running VMs/containers"
"status:Show VM/container status"
"show:Show properties of one or more VMs/containers"
2015-04-23 01:52:59 +03:00
"start:Start container as a service"
2016-06-06 18:06:20 +03:00
"stop:Stop container (equal to poweroff)"
2014-03-25 23:28:31 +04:00
"login:Get a login prompt on a VM/container"
2015-04-23 01:52:59 +03:00
"enable:Enable automatic container start at boot"
"disable:Disable automatic container start at boot"
2014-03-25 23:28:31 +04:00
"poweroff:Power off one or more VMs/containers"
"reboot:Reboot one or more VMs/containers"
2013-07-29 23:13:29 +04:00
"terminate:Terminate one or more VMs/containers"
"kill:Send signal to process or a VM/container"
2015-04-23 01:52:59 +03:00
"copy-to:Copy files from the host to a container"
"copy-from:Copy files from a container to the host"
"bind:Bind mount a path from the host into a container"
"list-images:Show available container and VM images"
"image-status:Show image details"
"show-image:Show properties of image"
"clone:Clone an image"
"rename:Rename an image"
"read-only:Mark or unmark image read-only"
"remove:Remove an image"
"pull-tar:Download a TAR container image"
"pull-raw:Download a RAW container or VM image"
"list-transfers:Show list of downloads in progress"
"cancel-transfer:Cancel a download"
2013-07-29 23:13:29 +04:00
)
2015-04-23 01:52:59 +03:00
2013-07-29 23:13:29 +04:00
if (( CURRENT == 1 )); then
_describe -t commands 'machinectl command' _machinectl_cmds || compadd "$@"
else
local curcontext="$curcontext"
cmd="${${_machinectl_cmds[(r)$words[1]:*]%%:*}}"
if (( $#cmd )); then
2015-04-23 01:52:59 +03:00
if (( CURRENT == 2 )); then
case $cmd in
2015-12-10 14:40:04 +03:00
list*|cancel-transfer|pull-tar|pull-raw)
2015-04-23 01:52:59 +03:00
msg="no options" ;;
2018-11-16 16:27:02 +03:00
clone)
2018-12-24 14:15:38 +03:00
_machinectl_machines ;;
2015-04-23 01:52:59 +03:00
start)
2018-12-24 14:15:38 +03:00
_machinectl_machines ;;
2015-04-23 01:52:59 +03:00
*)
_sd_machines
esac
else
case $cmd in
copy-to|copy-from|bind)
_files ;;
*) msg="no options"
esac
fi
2013-07-29 23:13:29 +04:00
else
_message "no more options"
fi
fi
}
_arguments \
{-h,--help}'[Prints a short help text and exits.]' \
'--version[Prints a short version string and exits.]' \
2015-04-23 01:52:59 +03:00
'--no-pager[Do not pipe output into a pager.]' \
'--no-legend[Do not show the headers and footers.]' \
'--no-ask-password[Do not ask for system passwords.]' \
{-H+,--host=}'[Operate on remote host.]:userathost:_sd_hosts_or_user_at_host' \
{-M+,--machine=}'[Operate on local container.]:machine:_sd_machines' \
{-p+,--property=}'[Limit output to specified property.]:property:(Name Id Timestamp TimestampMonotonic Service Scope Leader Class State RootDirectory)' \
2018-11-16 16:27:56 +03:00
{-a,--all}'[Show all properties.]' \
2015-04-23 01:52:59 +03:00
{-q,--quiet}'[Suppress output.]' \
{-l,--full}'[Do not ellipsize cgroup members.]' \
'--kill-who=[Who to send signal to.]:killwho:(leader all)' \
{-s+,--signal=}'[Which signal to send.]:signal:_signals' \
'--read-only[Create read-only bind mount.]' \
'--mkdir[Create directory before bind mounting, if missing.]' \
{-n+,--lines=}'[Number of journal entries to show.]:integer' \
{-o+,--output=}'[Change journal output mode.]:output modes:_sd_outputmodes' \
'--verify=[Verification mode for downloaded images.]:verify:(no checksum signature)' \
'--force[Download image even if already exists.]' \
2018-12-24 14:15:38 +03:00
'*::machinectl command:_machinectl_commands'