summaryrefslogtreecommitdiff
path: root/src/grp-machine/machinectl
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-08-07 21:03:44 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-08-07 21:03:44 -0400
commit2abe0f2d527c7b3f6b97bd6519bf0e35a266ea68 (patch)
tree02eb54ce46d51f11defb2c6481cd23ee006d39c0 /src/grp-machine/machinectl
parent09010ac6999db43e39cde92200fc4a10858f5c51 (diff)
stuff
Diffstat (limited to 'src/grp-machine/machinectl')
-rw-r--r--src/grp-machine/machinectl/machinectl.completion.bash99
-rw-r--r--src/grp-machine/machinectl/machinectl.completion.zsh99
2 files changed, 198 insertions, 0 deletions
diff --git a/src/grp-machine/machinectl/machinectl.completion.bash b/src/grp-machine/machinectl/machinectl.completion.bash
new file mode 100644
index 0000000000..e7829ca968
--- /dev/null
+++ b/src/grp-machine/machinectl/machinectl.completion.bash
@@ -0,0 +1,99 @@
+# machinectl(1) completion -*- shell-script -*-
+#
+# This file is part of systemd.
+#
+# Copyright 2014 Thomas H.P. Andersen
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+
+__contains_word() {
+ local w word=$1; shift
+ for w in "$@"; do
+ [[ $w = "$word" ]] && return
+ done
+}
+
+__get_machines() {
+ local a b
+ (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
+ { while read a b; do echo " $a"; done; } | sort -u;
+}
+
+_machinectl() {
+ local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
+ local i verb comps
+
+ local -A OPTS=(
+ [STANDALONE]='--all -a --full --help -h --no-ask-password --no-legend --no-pager --version'
+ [ARG]='--host -H --kill-who -M --machine --property -p --signal -s'
+ )
+
+ local -A VERBS=(
+ [STANDALONE]='list list-images pull-tar pull-raw import-tar import-raw export-tar export-raw list-transfers cancel-transfer'
+ [MACHINES]='status show start login shell enable disable poweroff reboot terminate kill copy-to copy-from image-status show-image clone rename read-only remove set-limit'
+ )
+
+ _init_completion || return
+
+ for ((i=0; i <= COMP_CWORD; i++)); do
+ if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
+ ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
+ verb=${COMP_WORDS[i]}
+ break
+ fi
+ done
+
+ if __contains_word "$prev" ${OPTS[ARG]}; then
+ case $prev in
+ --signal|-s)
+ _signals
+ return
+ ;;
+ --kill-who)
+ comps='all leader'
+ ;;
+ --host|-H)
+ comps=$(compgen -A hostname)
+ ;;
+ --machine|-M)
+ comps=$( __get_machines )
+ ;;
+ --property|-p)
+ comps=''
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ return 0
+ fi
+
+ if [[ "$cur" = -* ]]; then
+ COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
+ return 0
+ fi
+
+ if [[ -z $verb ]]; then
+ comps=${VERBS[*]}
+
+ elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
+ comps=''
+
+ elif __contains_word "$verb" ${VERBS[MACHINES]}; then
+ comps=$( __get_machines )
+ fi
+
+ COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ return 0
+}
+
+complete -F _machinectl machinectl
diff --git a/src/grp-machine/machinectl/machinectl.completion.zsh b/src/grp-machine/machinectl/machinectl.completion.zsh
new file mode 100644
index 0000000000..198fa28f7b
--- /dev/null
+++ b/src/grp-machine/machinectl/machinectl.completion.zsh
@@ -0,0 +1,99 @@
+#compdef machinectl
+
+__get_available_machines () {
+ machinectl --no-legend list-images | {while read -r a b; do echo $a; done;}
+}
+
+_available_machines() {
+ local -a _machines
+ _machines=("${(fo)$(__get_available_machines)}")
+ typeset -U _machines
+ if [[ -n "$_machines" ]]; then
+ _describe 'machines' _machines
+ else
+ _message 'no machines'
+ fi
+}
+
+(( $+functions[_machinectl_command] )) || _machinectl_command()
+{
+ 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"
+ "start:Start container as a service"
+ "login:Get a login prompt on a VM/container"
+ "enable:Enable automatic container start at boot"
+ "disable:Disable automatic container start at boot"
+ "poweroff:Power off one or more VMs/containers"
+ "reboot:Reboot one or more VMs/containers"
+ "terminate:Terminate one or more VMs/containers"
+ "kill:Send signal to process or a VM/container"
+ "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"
+ )
+
+ 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
+ if (( CURRENT == 2 )); then
+ case $cmd in
+ list*|cancel-transfer|pull-tar|pull-raw)
+ msg="no options" ;;
+ start)
+ _available_machines ;;
+ *)
+ _sd_machines
+ esac
+ else
+ case $cmd in
+ copy-to|copy-from|bind)
+ _files ;;
+ *) msg="no options"
+ esac
+ fi
+ 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.]' \
+ '--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)' \
+ {-a,--all}'[Show all proerties.]' \
+ {-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.]' \
+ '*::machinectl command:_machinectl_command'