| 192 |
- |
1 |
# bash completion for vdostats
|
|
|
2 |
#
|
| 203 |
- |
3 |
# Copyright Red Hat
|
| 192 |
- |
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and/or
|
|
|
6 |
# modify it under the terms of the GNU General Public License
|
|
|
7 |
# as published by the Free Software Foundation; either version 2
|
|
|
8 |
# of the License, or (at your option) any later version.
|
|
|
9 |
#
|
|
|
10 |
# This program is distributed in the hope that it will be useful,
|
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
13 |
# GNU General Public License for more details.
|
|
|
14 |
#
|
|
|
15 |
# You should have received a copy of the GNU General Public License
|
|
|
16 |
# along with this program; if not, write to the Free Software
|
|
|
17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
18 |
# 02110-1301, USA.
|
|
|
19 |
|
|
|
20 |
# If this needs to be modified where the location of confFile would be
|
|
|
21 |
# manually provided, we should be able to read from that file
|
|
|
22 |
|
|
|
23 |
CONF_FILE=/etc/vdoconf.yml
|
|
|
24 |
|
|
|
25 |
# This function will tokenize the INPUT that is given by the function
|
|
|
26 |
# _parse_vdo_options(). It will output all the options that have
|
|
|
27 |
# two "--" in the beginning.
|
|
|
28 |
|
|
|
29 |
__parse_vdo_options()
|
|
|
30 |
{
|
|
|
31 |
local option option2 i IFS=',/|';
|
|
|
32 |
option=;
|
|
|
33 |
local -a array;
|
|
|
34 |
if [[ $1 =~ --[A-Za-z0-9]+ ]] ; then
|
|
|
35 |
read -a array <<< "${BASH_REMATCH[0]}"
|
|
|
36 |
fi
|
|
|
37 |
for i in "${array[@]}";
|
|
|
38 |
do
|
|
|
39 |
case "$i" in
|
|
|
40 |
---*)
|
|
|
41 |
break
|
|
|
42 |
;;
|
|
|
43 |
--?*)
|
|
|
44 |
option=$i;
|
|
|
45 |
break
|
|
|
46 |
;;
|
|
|
47 |
-?*)
|
|
|
48 |
[[ -n $option ]] || option=$i
|
|
|
49 |
;;
|
|
|
50 |
*)
|
|
|
51 |
break
|
|
|
52 |
;;
|
|
|
53 |
esac;
|
|
|
54 |
done;
|
|
|
55 |
[[ -n $option ]] || return;
|
|
|
56 |
IFS='
|
|
|
57 |
';
|
|
|
58 |
if [[ $option =~ (\[((no|dont)-?)\]). ]]; then
|
|
|
59 |
option2=${option/"${BASH_REMATCH[1]}"/};
|
|
|
60 |
option2=${option2%%[<{().[]*};
|
|
|
61 |
printf '%s\n' "${option2/=*/=}";
|
|
|
62 |
option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"};
|
|
|
63 |
fi;
|
|
|
64 |
option=${option%%[<{().[]*};
|
|
|
65 |
printf '%s\n' "${option/=*/=}"
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
# This function does the hardwork of doing the following:
|
|
|
69 |
# let us assume you're running vdo activate
|
|
|
70 |
# It executes "vdo activate --help" and gets a list of possible
|
|
|
71 |
# options and then tokenizes them.
|
|
|
72 |
|
|
|
73 |
_parse_vdo_options()
|
|
|
74 |
{
|
|
|
75 |
eval local cmd=$( quote "$1" );
|
|
|
76 |
local line;
|
|
|
77 |
{
|
|
|
78 |
case $cmd in
|
|
|
79 |
-)
|
|
|
80 |
cat
|
|
|
81 |
;;
|
|
|
82 |
*)
|
|
|
83 |
LC_ALL=C "$( dequote "$cmd" )" $2 --help 2>&1
|
|
|
84 |
;;
|
|
|
85 |
esac
|
|
|
86 |
}| while read -r line; do
|
|
|
87 |
[[ $line == *([[:blank:]])-* ]] || continue;
|
|
|
88 |
while [[ $line =~ \
|
|
|
89 |
((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+\]? ]]; do
|
|
|
90 |
line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"};
|
|
|
91 |
done;
|
|
|
92 |
__parse_vdo_options "${line// or /, }";
|
|
|
93 |
done
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
# _vdo_devdir will give the list of devices that can be used
|
|
|
97 |
# for vdo
|
|
|
98 |
|
|
|
99 |
_vdo_devdir()
|
|
|
100 |
{
|
|
|
101 |
local cur prev words cword options
|
|
|
102 |
_init_completion || return
|
|
|
103 |
COMPREPLY=( $( compgen -W "$(lsblk -pnro name)" -- "$cur" ))
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
# We parse the configuration file to understand the names of vdo
|
|
|
107 |
# which are present. This may generate false positive if the
|
|
|
108 |
# conf file has names of vdo devices but they're not actually
|
|
|
109 |
# present in the system
|
|
|
110 |
|
|
|
111 |
_vdo_names()
|
|
|
112 |
{
|
|
|
113 |
local cur prev words cword options
|
|
|
114 |
_init_completion || return
|
|
|
115 |
if [ ! -f $CONF_FILE ]; then
|
|
|
116 |
return
|
|
|
117 |
fi
|
|
|
118 |
names=()
|
|
|
119 |
while IFS= read -r line
|
|
|
120 |
do
|
|
|
121 |
if [[ $line =~ \!VDOService ]]; then
|
|
|
122 |
names+=( $(echo $line | cut -d: -f1) )
|
|
|
123 |
fi
|
|
|
124 |
done < $CONF_FILE
|
|
|
125 |
COMPREPLY=( $( compgen -W " ${names[*]}" -- "$cur"))
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
_generic_function()
|
|
|
130 |
{
|
|
|
131 |
|
|
|
132 |
local cur prev words cword options
|
|
|
133 |
_init_completion || return
|
|
|
134 |
|
|
|
135 |
# We check for filename completion before after the first compreply.
|
|
|
136 |
# Otherwise the options of COMPREPLY and _filedir will be mixed.
|
|
|
137 |
case "${prev}" in
|
|
|
138 |
-f|--confFile)
|
|
|
139 |
# since the configuration file has the extention yml, we only display
|
|
|
140 |
# the files with the suffix yml.
|
|
|
141 |
_filedir yml
|
|
|
142 |
return
|
|
|
143 |
;;
|
|
|
144 |
--logfile)
|
|
|
145 |
_filedir
|
|
|
146 |
return
|
|
|
147 |
;;
|
|
|
148 |
esac
|
|
|
149 |
|
|
|
150 |
COMPREPLY=( $( compgen -W '$( _parse_vdo_options vdo $1 )' -- "$cur" ) )
|
|
|
151 |
case "${prev}" in
|
|
|
152 |
-n|--name)
|
|
|
153 |
if [[ "$1" == "create" ]]
|
|
|
154 |
then
|
|
|
155 |
return
|
|
|
156 |
else
|
|
|
157 |
_vdo_names
|
|
|
158 |
fi
|
|
|
159 |
;;
|
|
|
160 |
--writePolicy)
|
|
|
161 |
COMPREPLY=( $( compgen -W 'sync async auto' -- "$cur" ) )
|
|
|
162 |
;;
|
|
|
163 |
--activate|--compression|--deduplication|--emulate512|--sparseIndex)
|
|
|
164 |
COMPREPLY=( $( compgen -W 'disabled enabled' -- "$cur" ) )
|
|
|
165 |
;;
|
|
|
166 |
--vdoLogLevel)
|
|
|
167 |
COMPREPLY=( $( compgen -W \
|
|
|
168 |
'critical error warning notice info debug' -- "$cur" ) )
|
|
|
169 |
;;
|
|
|
170 |
--device)
|
|
|
171 |
_vdo_devdir
|
|
|
172 |
;;
|
|
|
173 |
|
|
|
174 |
esac
|
|
|
175 |
return
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
_vdo()
|
|
|
179 |
{
|
|
|
180 |
local cur prev words cword
|
|
|
181 |
_init_completion || return
|
|
|
182 |
|
|
|
183 |
if [[ $cword -eq 1 ]]; then
|
|
|
184 |
COMPREPLY=( $( compgen -W '
|
|
|
185 |
activate changeWritePolicy create deactivate disableCompression
|
|
|
186 |
disableDeduplication enableCompression enableDeduplication growLogical
|
|
|
187 |
growPhysical list modify printConfigFile remove start status
|
|
|
188 |
stop' -- "$cur" ) )
|
|
|
189 |
else
|
|
|
190 |
case "${words[1]}" in
|
|
|
191 |
activate|changeWritePolicy|create|deactivate|disableCompression|\
|
|
|
192 |
disableDeduplication|enableCompression|enableDeduplication|\
|
|
|
193 |
growLogical|growPhysical|list|modify|printConfigFile|remove|\
|
|
|
194 |
start|status|stop)
|
|
|
195 |
_generic_function ${words[1]}
|
|
|
196 |
;;
|
|
|
197 |
esac
|
|
|
198 |
fi
|
|
|
199 |
} &&
|
|
|
200 |
|
|
|
201 |
complete -F _vdo vdo
|