Debian Codegraph @

shell-completion/bash/systemd-vmspawn

raw
1 # shellcheck shell=bash
2 # systemd-vmspawn(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
4 #
5 # This file is part of systemd.
6 #
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
11 #
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
19
20 __contains_word() {
21 local w word=$1; shift
22 for w in "$@"; do
23 [[ $w = "$word" ]] && return
24 done
25 }
26
27 _systemd_vmspawn() {
28 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
29 local i verb comps
30
31 local -A OPTS=(
32 [STANDALONE]='-h --help --version -q --quiet --no-pager -n --network-tap --network-user-mode --user --system -x --ephemeral'
33 [PATH]='-D --directory -i --image --linux --initrd --extra-drive --forward-journal --efi-nvram-template'
34 [BOOL]='--kvm --vsock --tpm --discard-disk --pass-ssh-key'
35 [TRISTATE]='--register --secure-boot'
36 [FIRMWARE]='--firmware'
37 [FIRMWARE_FEATURES]='--firmware-features'
38 [BIND]='--bind --bind-ro'
39 [SSH_KEY]='--ssh-key'
40 [CONSOLE]='--console'
41 [ARG]='--cpus --ram --vsock-cid -M --machine --uuid --private-users --background --set-credential --load-credential --forward-journal-max-use --forward-journal-keep-free --forward-journal-max-file-size --forward-journal-max-files --bind-volume'
42 [IMAGE_FORMAT]='--image-format'
43 [IMAGE_DISK_TYPE]='--image-disk-type'
44 [COCO]='--coco'
45 )
46
47 _init_completion || return
48
49 if __contains_word "$prev" ${OPTS[BOOL]}; then
50 comps='yes no'
51 elif __contains_word "$prev" ${OPTS[TRISTATE]}; then
52 comps='yes no auto'
53 elif __contains_word "$prev" ${OPTS[PATH]}; then
54 compopt -o nospace -o filenames
55 comps=$(compgen -f -- "$cur" )
56 elif __contains_word "$prev" ${OPTS[FIRMWARE]}; then
57 compopt -o nospace -o filenames
58 comps="list describe $(compgen -f -- "$cur" )"
59 elif __contains_word "$prev" ${OPTS[FIRMWARE_FEATURES]}; then
60 comps='list'
61 elif __contains_word "$prev" ${OPTS[BIND]}; then
62 compopt -o nospace -o filenames
63 comps=$(compgen -f -- "${cur}" )
64 elif __contains_word "$prev" ${OPTS[SSH_KEY]}; then
65 comps='dsa ecdsa ecdsa-sk ed25519 ed25519-sk rsa'
66 elif __contains_word "$prev" ${OPTS[CONSOLE]}; then
67 comps='interactive native gui read-only headless'
68 elif __contains_word "$prev" ${OPTS[IMAGE_FORMAT]}; then
69 comps='raw qcow2'
70 elif __contains_word "$prev" ${OPTS[IMAGE_DISK_TYPE]}; then
71 comps='virtio-blk virtio-scsi nvme'
72 elif __contains_word "$prev" ${OPTS[COCO]}; then
73 comps='no sev-snp'
74 elif __contains_word "$prev" ${OPTS[ARG]}; then
75 comps=''
76 else
77 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
78 return 0
79 fi
80 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
81 return 0
82
83 }
84
85 complete -F _systemd_vmspawn systemd-vmspawn