]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/zsh/_machinectl
Merge pull request #10221 from lucaswerkmeister/bash-completion
[thirdparty/systemd.git] / shell-completion / zsh / _machinectl
1 #compdef machinectl
2 # SPDX-License-Identifier: LGPL-2.1+
3
4 __get_available_machines () {
5 machinectl --no-legend list-images | {while read -r a b; do echo $a; done;}
6 }
7
8 _available_machines() {
9 local -a _machines
10 _machines=("${(fo)$(__get_available_machines)}")
11 typeset -U _machines
12 if [[ -n "$_machines" ]]; then
13 _describe 'machines' _machines
14 else
15 _message 'no machines'
16 fi
17 }
18
19 (( $+functions[_machinectl_command] )) || _machinectl_command()
20 {
21 local -a _machinectl_cmds
22 _machinectl_cmds=(
23 "list:List currently running VMs/containers"
24 "status:Show VM/container status"
25 "show:Show properties of one or more VMs/containers"
26 "start:Start container as a service"
27 "stop:Stop container (equal to poweroff)"
28 "login:Get a login prompt on a VM/container"
29 "enable:Enable automatic container start at boot"
30 "disable:Disable automatic container start at boot"
31 "poweroff:Power off one or more VMs/containers"
32 "reboot:Reboot one or more VMs/containers"
33 "terminate:Terminate one or more VMs/containers"
34 "kill:Send signal to process or a VM/container"
35 "copy-to:Copy files from the host to a container"
36 "copy-from:Copy files from a container to the host"
37 "bind:Bind mount a path from the host into a container"
38
39 "list-images:Show available container and VM images"
40 "image-status:Show image details"
41 "show-image:Show properties of image"
42 "clone:Clone an image"
43 "rename:Rename an image"
44 "read-only:Mark or unmark image read-only"
45 "remove:Remove an image"
46
47 "pull-tar:Download a TAR container image"
48 "pull-raw:Download a RAW container or VM image"
49 "list-transfers:Show list of downloads in progress"
50 "cancel-transfer:Cancel a download"
51 )
52
53 if (( CURRENT == 1 )); then
54 _describe -t commands 'machinectl command' _machinectl_cmds || compadd "$@"
55 else
56 local curcontext="$curcontext"
57 cmd="${${_machinectl_cmds[(r)$words[1]:*]%%:*}}"
58 if (( $#cmd )); then
59 if (( CURRENT == 2 )); then
60 case $cmd in
61 list*|cancel-transfer|pull-tar|pull-raw)
62 msg="no options" ;;
63 clone)
64 _available_machines ;;
65 start)
66 _available_machines ;;
67 *)
68 _sd_machines
69 esac
70 else
71 case $cmd in
72 copy-to|copy-from|bind)
73 _files ;;
74 *) msg="no options"
75 esac
76 fi
77 else
78 _message "no more options"
79 fi
80 fi
81 }
82
83 _arguments \
84 {-h,--help}'[Prints a short help text and exits.]' \
85 '--version[Prints a short version string and exits.]' \
86 '--no-pager[Do not pipe output into a pager.]' \
87 '--no-legend[Do not show the headers and footers.]' \
88 '--no-ask-password[Do not ask for system passwords.]' \
89 {-H+,--host=}'[Operate on remote host.]:userathost:_sd_hosts_or_user_at_host' \
90 {-M+,--machine=}'[Operate on local container.]:machine:_sd_machines' \
91 {-p+,--property=}'[Limit output to specified property.]:property:(Name Id Timestamp TimestampMonotonic Service Scope Leader Class State RootDirectory)' \
92 {-a,--all}'[Show all properties.]' \
93 {-q,--quiet}'[Suppress output.]' \
94 {-l,--full}'[Do not ellipsize cgroup members.]' \
95 '--kill-who=[Who to send signal to.]:killwho:(leader all)' \
96 {-s+,--signal=}'[Which signal to send.]:signal:_signals' \
97 '--read-only[Create read-only bind mount.]' \
98 '--mkdir[Create directory before bind mounting, if missing.]' \
99 {-n+,--lines=}'[Number of journal entries to show.]:integer' \
100 {-o+,--output=}'[Change journal output mode.]:output modes:_sd_outputmodes' \
101 '--verify=[Verification mode for downloaded images.]:verify:(no checksum signature)' \
102 '--force[Download image even if already exists.]' \
103 '*::machinectl command:_machinectl_command'