summaryrefslogtreecommitdiffstats
path: root/completions/_xm
blob: 7577efd22d2a5a5c9a20540b70d8eb3f4bde0f76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# bash completion for xm                                   -*- shell-script -*-

# Use of this file is deprecated.  The 'xm' command itself is no longer
# provided by upstream.  It has been replaced with the 'xl' command, for
# which upstream provides completion, use that instead.

_comp_cmd_xm__domain_names()
{
    _comp_compgen_split -- "$(xm list 2>/dev/null |
        _comp_awk '!/Name|Domain-0/ { print $1 }')"
}

_comp_cmd_xm()
{
    local cur prev words cword comp_args
    _comp_initialize -- "$@" || return

    # TODO: split longopt

    local REPLY command commands options

    commands='console vncviewer create new delete destroy domid domname
        dump-core list mem-max mem-set migrate pause reboot rename reset
        restore resume save shutdown start suspend sysrq trigger top unpause
        uptime usb-add usb-del vcpu-list vcpu-pin vcpu-set debug-keys dmesg
        info log serve sched-credit sched-sedf block-attach block-detach
        block-list block-configure network-attach network-detach network-list
        vtpm-list pci-attach pci-detach pci-list pci-list-assignable-devices
        scsi-attach scsi-detach scsi-list vnet-list vnet-create vnet-delete
        labels addlabel rmlabel getlabel dry-run resources dumppolicy setpolicy
        resetpolicy getpolicy shell help'

    if ((cword == 1)); then
        _comp_compgen -- -W "$commands"
    else
        if [[ $cur == *=* ]]; then
            prev=${cur/=*/}
            cur=${cur/*=/}
        fi

        command=${words[1]}
        if [[ $cur == -* ]]; then
            # possible options for the command
            case $command in
                create)
                    options='-c'
                    ;;
                dmesg)
                    options='--clear'
                    ;;
                list)
                    options='--long'
                    ;;
                reboot)
                    options='-w -a'
                    ;;
                shutdown)
                    options='-w -a -R -H'
                    ;;
                sched-credit)
                    options='-d -w -c'
                    ;;
                block-list | network-list | vtpm-list | vnet-list)
                    options='-l --long'
                    ;;
                getpolicy)
                    options='--dumpxml'
                    ;;
                new)
                    options='-h --help --help_config -q --quiet --path= -f=
                        --defconfig= -F= --config= -b --dryrun -x --xmldryrun
                        -s --skipdtd -p --paused -c --console_autoconnect'
                    ;;
            esac
            _comp_compgen -- -W "$options"
        else
            case $command in
                console | destroy | domname | domid | list | mem-set | \
                    mem-max | pause | reboot | rename | shutdown | unpause | \
                    vcpu-list | vcpu-pin | vcpu-set | block-list | \
                    network-list | vtpm-list)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                    esac
                    ;;
                migrate)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                        3)
                            _comp_compgen_known_hosts -- "$cur"
                            ;;
                    esac
                    ;;
                restore | dry-run | vnet-create)
                    _comp_compgen_filedir
                    ;;
                save)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                        3)
                            _comp_compgen_filedir
                            ;;
                    esac
                    ;;
                sysrq)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                        3)
                            _comp_compgen -- -W "r s e i u b"
                            ;;
                    esac
                    ;;
                block-attach)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                        3)
                            _comp_compgen -- -W "phy: file:"
                            ;;
                        5)
                            _comp_compgen -- -W "w r"
                            ;;
                        6)
                            _comp_cmd_xm__domain_names
                            ;;
                    esac
                    ;;
                block-detach)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                        3)
                            _comp_compgen_split -- "$(xm block-list "$prev" \
                                2>/dev/null | _comp_awk '!/Vdev/ { print $1 }')"
                            ;;
                    esac
                    ;;
                network-attach)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                        *)
                            _comp_compgen -- -W "script= ip= mac= bridge=
                                backend="
                            ;;
                    esac
                    ;;
                network-detach)
                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                        3)
                            _comp_compgen_split -- "$(xm network-list "$prev" \
                                2>/dev/null | _comp_awk '!/Idx/ { print $1 }')"
                            ;;
                    esac
                    ;;
                sched-credit)
                    case $prev in
                        -d)
                            _comp_cmd_xm__domain_names
                            return
                            ;;
                    esac
                    ;;
                create)
                    _comp_compgen_filedir
                    _comp_compgen -a split -- "$(
                        command ls /etc/xen 2>/dev/null
                    )"
                    ;;
                new)
                    case $prev in
                        -f | -F | --defconfig | --config)
                            _comp_compgen_filedir
                            return
                            ;;
                        --path)
                            _comp_compgen_filedir -d
                            return
                            ;;
                    esac

                    _comp_count_args
                    case $REPLY in
                        2)
                            _comp_cmd_xm__domain_names
                            ;;
                    esac
                    ;;
            esac
        fi
    fi
} &&
    complete -F _comp_cmd_xm xm

# ex: filetype=sh