| 1 |
#compdef machinectl |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
(( $+functions[__machinectl_get_images] )) || |
| 5 |
__machinectl_get_images () { |
| 6 |
local -a flags |
| 7 |
if [[ $PREFIX == .* ]]; then flags=( --all ); fi |
| 8 |
machinectl --no-legend list-images $flags 2>/dev/null | {while read -r a b; do |
| 9 |
# escape : and \; do not interpret existing escape sequences |
| 10 |
printf -- "%s\n" ${a//(#b)(\\|:)/\\$match} |
| 11 |
done;} |
| 12 |
} |
| 13 |
|
| 14 |
(( $+functions[_machinectl_images] )) || |
| 15 |
_machinectl_images() { |
| 16 |
local -a _machines |
| 17 |
_machines=("${(fo)$(__machinectl_get_images)}") |
| 18 |
typeset -U _machines |
| 19 |
if [[ -n "$_machines" ]]; then |
| 20 |
_describe 'images' _machines |
| 21 |
else |
| 22 |
_message 'no images' |
| 23 |
fi |
| 24 |
} |
| 25 |
|
| 26 |
(( $+functions[_machinectl_commands] )) || _machinectl_commands() |
| 27 |
{ |
| 28 |
local -a _machinectl_cmds |
| 29 |
_machinectl_cmds=( |
| 30 |
"list:List currently running VMs/containers" |
| 31 |
"status:Show VM/container status" |
| 32 |
"show:Show properties of one or more VMs/containers" |
| 33 |
"start:Start container as a service" |
| 34 |
"stop:Stop container (equal to poweroff)" |
| 35 |
"login:Get a login prompt on a VM/container" |
| 36 |
"shell:Invoke a shell (or other command) in a container" |
| 37 |
"enable:Enable automatic container start at boot" |
| 38 |
"disable:Disable automatic container start at boot" |
| 39 |
"poweroff:Power off one or more VMs/containers" |
| 40 |
"reboot:Reboot one or more VMs/containers" |
| 41 |
"pause:Pause one or more machines" |
| 42 |
"resume:Resume one or more previously paused machines" |
| 43 |
"terminate:Terminate one or more VMs/containers" |
| 44 |
"kill:Send signal to process or a VM/container" |
| 45 |
"copy-to:Copy files from the host to a container" |
| 46 |
"copy-from:Copy files from a container to the host" |
| 47 |
"bind:Bind mount a path from the host into a container" |
| 48 |
"bind-volume:Attach a storage volume to a running machine" |
| 49 |
"unbind-volume:Detach a storage volume from a running machine" |
| 50 |
|
| 51 |
"list-images:Show available container and VM images" |
| 52 |
"image-status:Show image details" |
| 53 |
"show-image:Show properties of image" |
| 54 |
"edit:Edit settings of one or more VMs/containers" |
| 55 |
"cat:Show settings of one or more VMs/containers" |
| 56 |
"clone:Clone an image" |
| 57 |
"rename:Rename an image" |
| 58 |
"read-only:Mark or unmark image read-only" |
| 59 |
"remove:Remove an image" |
| 60 |
"set-limits:Set image or pool size limit (disk quota)" |
| 61 |
"clean:Remove hidden (or all) images" |
| 62 |
|
| 63 |
"pull-tar:Download a TAR container image" |
| 64 |
"pull-raw:Download a RAW container or VM image" |
| 65 |
"import-tar:Import a local TAR container image" |
| 66 |
"import-raw:Import a local RAW container or VM image" |
| 67 |
"import-fs:Import a local directory container image" |
| 68 |
"export-tar:Export a TAR container image locally" |
| 69 |
"export-raw:Export a RAW container or VM image locally" |
| 70 |
"list-transfers:Show list of downloads in progress" |
| 71 |
"cancel-transfer:Cancel a download" |
| 72 |
) |
| 73 |
|
| 74 |
if (( CURRENT == 1 )); then |
| 75 |
_describe -t commands 'machinectl command' _machinectl_cmds || compadd "$@" |
| 76 |
else |
| 77 |
local curcontext="$curcontext" |
| 78 |
local stop=0 |
| 79 |
cmd="${${_machinectl_cmds[(r)$words[1]:*]%%:*}}" |
| 80 |
case $cmd in |
| 81 |
start|enable|disable) |
| 82 |
_machinectl_images ;; |
| 83 |
|
| 84 |
status|show|poweroff|reboot|pause|resume|terminate|kill) |
| 85 |
_sd_machines ;; |
| 86 |
|
| 87 |
login|shell) |
| 88 |
if (( CURRENT == 2 )); then _sd_machines |
| 89 |
else stop=1 |
| 90 |
fi ;; |
| 91 |
|
| 92 |
copy-to|bind) |
| 93 |
if (( CURRENT == 2 )); then _sd_machines |
| 94 |
elif (( CURRENT == 3 )); then _files |
| 95 |
elif (( CURRENT == 4 )); then _message "path on container" |
| 96 |
else stop=1 |
| 97 |
fi ;; |
| 98 |
|
| 99 |
copy-from) |
| 100 |
if (( CURRENT == 2 )); then _sd_machines |
| 101 |
elif (( CURRENT == 3 )); then _message "path on container" |
| 102 |
elif (( CURRENT == 4 )); then _files |
| 103 |
else stop=1 |
| 104 |
fi ;; |
| 105 |
|
| 106 |
image-status|show-image|remove) |
| 107 |
_machinectl_images ;; |
| 108 |
|
| 109 |
edit|cat) |
| 110 |
if (( CURRENT == 2 )); then _machinectl_images |
| 111 |
else stop=1 |
| 112 |
fi ;; |
| 113 |
|
| 114 |
clone|rename) |
| 115 |
if (( CURRENT == 2 )); then _machinectl_images |
| 116 |
elif (( CURRENT == 3 )); then _message "target image" |
| 117 |
else stop=1 |
| 118 |
fi ;; |
| 119 |
|
| 120 |
bind-volume|unbind-volume) |
| 121 |
if (( CURRENT == 2 )); then _sd_machines |
| 122 |
elif (( CURRENT == 3 )); then _message "volume spec" |
| 123 |
else stop=1 |
| 124 |
fi ;; |
| 125 |
|
| 126 |
read-only) |
| 127 |
if (( CURRENT == 2 )); then _machinectl_images |
| 128 |
elif (( CURRENT == 3 )); then _values 'read-only flag' 'true' 'false' |
| 129 |
else stop=1 |
| 130 |
fi ;; |
| 131 |
|
| 132 |
set-limit) |
| 133 |
if (( CURRENT == 2 )); then _machinectl_images |
| 134 |
elif (( CURRENT == 3 )); then _message "size limit" |
| 135 |
else stop=1 |
| 136 |
fi ;; |
| 137 |
|
| 138 |
pull-tar|pull-raw) |
| 139 |
if (( CURRENT == 2 )); then _message "${cmd#pull-} file URL" |
| 140 |
elif (( CURRENT == 3 )); then _message "target image" |
| 141 |
else stop=1 |
| 142 |
fi ;; |
| 143 |
|
| 144 |
import-tar) |
| 145 |
if (( CURRENT == 2 )); then _files -g "*.(tar(|.(gz|bz2|xz|zst))|tgz|tbz2|txz|tzst)(.)" |
| 146 |
elif (( CURRENT == 3 )); then _message "target image" |
| 147 |
else stop=1 |
| 148 |
fi ;; |
| 149 |
import-raw) |
| 150 |
if (( CURRENT == 2 )); then _files -g "*(.)" |
| 151 |
elif (( CURRENT == 3 )); then _message "target image" |
| 152 |
else stop=1 |
| 153 |
fi ;; |
| 154 |
import-fs) |
| 155 |
if (( CURRENT == 2 )); then _files -/ |
| 156 |
elif (( CURRENT == 3 )); then _message "target image" |
| 157 |
else stop=1 |
| 158 |
fi ;; |
| 159 |
|
| 160 |
export-tar|export-raw) |
| 161 |
if (( CURRENT == 2 )); then _machinectl_images |
| 162 |
elif (( CURRENT == 3 )); then _files |
| 163 |
else stop=1 |
| 164 |
fi ;; |
| 165 |
|
| 166 |
list*|clean|cancel-transfer) |
| 167 |
stop=1 ;; |
| 168 |
|
| 169 |
'') |
| 170 |
stop=1 ;; |
| 171 |
esac |
| 172 |
|
| 173 |
if (( stop )); then |
| 174 |
_message "no more options" |
| 175 |
return 1 |
| 176 |
fi |
| 177 |
fi |
| 178 |
} |
| 179 |
|
| 180 |
_arguments \ |
| 181 |
'(- *)'{-h,--help}'[Prints a short help text and exits.]' \ |
| 182 |
'(- *)--version[Prints a short version string and exits.]' \ |
| 183 |
'--no-pager[Do not pipe output into a pager.]' \ |
| 184 |
'--no-legend[Do not show the headers and footers.]' \ |
| 185 |
'--no-ask-password[Do not ask for system passwords.]' \ |
| 186 |
'(-H --host)'{-H+,--host=}'[Operate on remote host.]:userathost:_sd_hosts_or_user_at_host' \ |
| 187 |
'(-M --machine)'{-M+,--machine=}'[Operate on local container.]:machine:_sd_machines' \ |
| 188 |
'(-p --property)'{-p+,--property=}'[Limit output to specified property.]:property:(Name Id Timestamp TimestampMonotonic Service Scope Leader Class State RootDirectory)' \ |
| 189 |
'(-a --all)'{-a,--all}'[Show all properties.]' \ |
| 190 |
'(-q --quiet)'{-q,--quiet}'[Suppress output.]' \ |
| 191 |
'(-l --full)'{-l,--full}'[Do not ellipsize cgroup members.]' \ |
| 192 |
'--kill-whom=[Whom to send signal to.]:killwhom:(leader all)' \ |
| 193 |
'(-s --signal)'{-s+,--signal=}'[Which signal to send.]:signal:_signals' \ |
| 194 |
'--read-only[Create read-only bind mount.]' \ |
| 195 |
'--mkdir[Create directory before bind mounting, if missing.]' \ |
| 196 |
'(-n --lines)'{-n+,--lines=}'[Number of journal entries to show.]:integer' \ |
| 197 |
'(-o --output)'{-o+,--output=}'[Change journal output mode.]:output modes:_sd_outputmodes' \ |
| 198 |
'--verify=[Verification mode for downloaded images.]:verify:(no checksum signature)' \ |
| 199 |
'--force[Download image even if already exists.]' \ |
| 200 |
'*::machinectl command:_machinectl_commands' |