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