439b7ce868810427712ca146b94b7fb004abfbb4William Giokas#compdef machinectl
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak__get_available_machines () {
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak machinectl --no-legend list-images | {while read -r a b; do echo $a; done;}
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak}
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak_available_machines() {
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak local -a _machines
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak _machines=("${(fo)$(__get_available_machines)}")
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak typeset -U _machines
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak if [[ -n "$_machines" ]]; then
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak _describe 'machines' _machines
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak else
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak _message 'no machines'
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak fi
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak}
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas(( $+functions[_machinectl_command] )) || _machinectl_command()
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas{
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas local -a _machinectl_cmds
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas _machinectl_cmds=(
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas "list:List currently running VMs/containers"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas "status:Show VM/container status"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas "show:Show properties of one or more VMs/containers"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "start:Start container as a service"
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack "login:Get a login prompt on a VM/container"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "enable:Enable automatic container start at boot"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "disable:Disable automatic container start at boot"
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack "poweroff:Power off one or more VMs/containers"
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack "reboot:Reboot one or more VMs/containers"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas "terminate:Terminate one or more VMs/containers"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas "kill:Send signal to process or a VM/container"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "copy-to:Copy files from the host to a container"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "copy-from:Copy files from a container to the host"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "bind:Bind mount a path from the host into a container"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "list-images:Show available container and VM images"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "image-status:Show image details"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "show-image:Show properties of image"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "clone:Clone an image"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "rename:Rename an image"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "read-only:Mark or unmark image read-only"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "remove:Remove an image"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "pull-tar:Download a TAR container image"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "pull-raw:Download a RAW container or VM image"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "list-transfers:Show list of downloads in progress"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak "cancel-transfer:Cancel a download"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas )
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas if (( CURRENT == 1 )); then
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas _describe -t commands 'machinectl command' _machinectl_cmds || compadd "$@"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas else
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas local curcontext="$curcontext"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas cmd="${${_machinectl_cmds[(r)$words[1]:*]%%:*}}"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas if (( $#cmd )); then
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak if (( CURRENT == 2 )); then
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak case $cmd in
b43d75c378d919900e5c1e82a82e3e17dd3de9f9Lennart Poettering list*|cancel-transfer|pull-tar|pull-raw)
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak msg="no options" ;;
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak start)
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak _available_machines ;;
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak *)
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak _sd_machines
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak esac
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak else
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak case $cmd in
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak copy-to|copy-from|bind)
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak _files ;;
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak *) msg="no options"
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak esac
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak fi
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas else
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas _message "no more options"
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas fi
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas fi
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas}
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas_arguments \
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas {-h,--help}'[Prints a short help text and exits.]' \
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas '--version[Prints a short version string and exits.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--no-pager[Do not pipe output into a pager.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--no-legend[Do not show the headers and footers.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--no-ask-password[Do not ask for system passwords.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-H+,--host=}'[Operate on remote host.]:userathost:_sd_hosts_or_user_at_host' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-M+,--machine=}'[Operate on local container.]:machine:_sd_machines' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-p+,--property=}'[Limit output to specified property.]:property:(Name Id Timestamp TimestampMonotonic Service Scope Leader Class State RootDirectory)' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-a,--all}'[Show all proerties.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-q,--quiet}'[Suppress output.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-l,--full}'[Do not ellipsize cgroup members.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--kill-who=[Who to send signal to.]:killwho:(leader all)' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-s+,--signal=}'[Which signal to send.]:signal:_signals' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--read-only[Create read-only bind mount.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--mkdir[Create directory before bind mounting, if missing.]' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-n+,--lines=}'[Number of journal entries to show.]:integer' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak {-o+,--output=}'[Change journal output mode.]:output modes:_sd_outputmodes' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--verify=[Verification mode for downloaded images.]:verify:(no checksum signature)' \
b3b9282d0c79b108ed87abff5de6891617fe0602Lukas Rusak '--force[Download image even if already exists.]' \
439b7ce868810427712ca146b94b7fb004abfbb4William Giokas '*::machinectl command:_machinectl_command'