-
Notifications
You must be signed in to change notification settings - Fork 217
/
mock
213 lines (194 loc) · 6.14 KB
/
mock
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
# bash >= 3 completion for mock(1)
_mock_root()
{
test $# -eq 0 && set -- /etc/mock "$HOME/.config/mock"
local suggest=$(
shopt -s nullglob
for dir in "$@"; do
# work with absolute paths!
cd "$dir" &>/dev/null || continue
for file in *; do
case $file in
site-defaults*) ;; # skip site defaults
*' '*) ;; # skip files with white spaces
*.cfg) echo "${file%%.cfg}" ;;
esac
done
done
)
COMPREPLY+=( $( compgen -W "$suggest" -- "$cur" ) )
_filedir 'cfg'
}
_mock_isopt()
{
[[ ${1:0:1} = - ]] && return 0
case $1 in
install|remove)
return 0
;;
esac
return 1
}
_mock_isopt_multiarg() {
local the_option=$1
_mock_isopt "$the_option" || return 1
case $the_option in
--*)
the_option=${the_option##--}
;;
esac
case $the_option in
rebuild|install|installdeps|remove|chain|update|copyin|copyout|pm-cmd|yum-cmd|dnf-cmd|chroot|shell)
return 0
;;
esac
return 1
}
_mock_parse_help()
{
# PRECOMPILED_PARSED_MOCK_HELP
_parse_help "$1"
}
_mock()
{
local cur prev words cword split
_init_completion -s || return
local cfgdirs=( /etc/mock "$HOME/.config/mock" )
local count=0
local greedyopt=rebuild # the default mode eating srpms
local prevopt=rebuild
for word in "${words[@]}" ; do
if [[ $count -eq $cword ]] ; then
# If the last (i.e. current) argument is an option, clear prevopt so that we complete
# the current argument as an option instead an argument to prevopt
_mock_isopt "$word" && prevopt=
break
fi
# Record the option argument previous to the current argument to determine the type of
# completion that is needed
if _mock_isopt_multiarg "$word"; then
prevopt=$word
# last greedy option wins
greedyopt=$word
elif _mock_isopt "$word"; then
prevopt=$word
else
# Revert back to the last greedy option. E.g. for 'mock -r fedora-rawhide-x86_64 <tab>',
# we want to react on the default 'rebuild' mode, not `-r`.
prevopt=$greedyopt
fi
if [[ "$word" == --configdir ]] ; then
cfgdirs=( "${words[((count+1))]}" )
elif [[ "$word" == --configdir=* ]] ; then
cfgdirs=( ${word/*=/} )
fi
count=$((++count))
done
case "$prevopt" in
-h|--help|--version)
# no further arguments are accepted after the above arguments
return
;;
--arch|--config-opts|-D|--define|--disablerepo|--enablerepo|--forcearch|--plugin-option|\
--rpmbuild-opts|--rpmbuild_timeout|--scm-option|--uniqueext|--with|--without)
# argument required but no completions available
return
;;
-r|--root|--chain)
_mock_root "${cfgdirs[@]}"
return
;;
--configdir|--cwd|--resultdir|--rootdir)
_filedir -d
return
;;
--copyin|--copyout|--macro-file|--sources)
_filedir
return
;;
--spec)
_filedir 'spec'
return
;;
--target)
# Yep, compatible archs, not compatible build archs
# (e.g. ix86 chroot builds in x86_64 mock host)
# This would actually depend on what the target root
# can be used to build for...
COMPREPLY=( $( compgen -W "$( command rpm --showrc | \
sed -ne 's/^\s*compatible\s\s*archs\s*:\s*\(.*\)/\1/i p' )" \
-- "$cur" ) )
return
;;
--enable-plugin|--disable-plugin)
COMPREPLY=( $( compgen -W "$( $1 $prev=DOES_NOT_EXIST 2>&1 | \
sed -ne "s/[',]//g" -e 's/.*[[(]\([^])]*\)[])]/\1/p' )" \
-- "$cur" ) ) #' unconfuse emacs
return
;;
--scrub)
COMPREPLY=( $( compgen -W "all chroot cache root-cache c-cache
yum-cache dnf-cache lvm overlayfs bootstrap" -- "$cur" ) )
return
;;
-i|--install|install)
_filedir 'rpm'
COMPREPLY=( $( compgen -W '"${COMPREPLY[@]}"' -X '*.src.rpm' ) )
COMPREPLY=( $( compgen -W '"${COMPREPLY[@]}"' -X '*.nosrc.rpm' ) )
[[ $cur != */* && $cur != [.~]* ]] && \
declare -F _yum_list &>/dev/null && _yum_list all "$cur"
return
;;
--isolation)
COMPREPLY=( $( compgen -W "auto simple nspawn" -- "$cur" ) )
return
;;
--remove|remove)
declare -F _yum_list &>/dev/null && _yum_list all "$cur"
return
;;
--short-circuit)
COMPREPLY=( $( compgen -W "install binary build prep" -- "$cur" ) )
return
;;
esac
$split && return
if [[ "$cur" == -* ]] ; then
COMPREPLY=( $( compgen -W '$( _mock_parse_help "$1" )' -- "$cur" ) )
# _parse_help fails to pick up --define (it's a parsing failure due to
# the quoted 'MACRO EXPR' argument)
COMPREPLY+=( $( compgen -W '--define=' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
else
_filedir '@(?(no)src.r|s)pm'
fi
} &&
complete -F _mock mock mock.py
_mock_parse_buildlog()
{
local cur prev cword split
_init_completion -s || return
case "$prev" in
-h|--help)
# no further arguments are accepted after the above arguments
return
;;
-p|--path)
_filedir
return
;;
esac
$split && return
if [[ $cword -eq 1 ]] ; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
fi
} &&
complete -F _mock_parse_buildlog mock-parse-buildlog mock-parse-buildlog.py
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh