This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
10updocker-completion.bash
executable file
·295 lines (280 loc) · 10.7 KB
/
10updocker-completion.bash
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#/usr/bin/env bash
_compreply() {
local options="$*"
local cur_word="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=($(compgen -W "${options}" -- "${cur_word}"))
return 0
}
_10updocker_environments_completion() {
local env_utils="$( cd "$( dirname "$( dirname "${BASH_SOURCE[0]}" )" )" >/dev/null 2>&1 && pwd )"
local script="
(async () => {
let envs = [];
try {
envs = await require('${env_utils}/src/env-utils.js').getAllEnvironments();
} catch( e ) {
}
envs.push( 'all' );
process.stdout.write( envs.join( ' ' ) );
})();
"
_compreply "$(node -e "$script")"
return 0
}
_10updocker_completion() {
# Unfortunately, if we want to use "wp cli completions" command, we need to execute this command within a container,
# but we don't know which environment we need to use and whether it is started or not. So we fallback to the list of
# main commands defined on the official site: https://developer.wordpress.org/cli/commands/
local wp_commands=(
"admin" "cache" "cap" "cli" "comment" "config" "core" "cron" "db" "dist-archive" "embed" "eval" "eval-file"
"export" "find" "help" "i18n" "import" "language" "maintenance-mode" "media" "menu" "network" "option" "package"
"plugin" "post" "post-type" "profile" "rewrite" "role" "scaffold" "search-replace" "server" "shell" "sidebar"
"site" "super-admin" "taxonomy" "term" "theme" "transient" "user" "widget"
)
if [ ${COMP_CWORD} -eq 1 ]; then
_compreply cache configure create new delete remove rm image logs list ls cert migrate restart shell start stop wp wpspanshots spanshots upgrade
elif [ ${COMP_CWORD} -eq 2 ]; then
case ${COMP_WORDS[1]} in
cache)
_compreply clear
;;
image)
_compreply update
;;
delete | remove | start | stop | restart)
_10updocker_environments_completion
;;
wp)
_compreply "${wp_commands[@]}"
;;
cert)
_compreply install generate
;;
esac
elif [ ${COMP_CWORD} -eq 3 ]; then
case ${COMP_WORDS[1]} in
migrate)
_10updocker_environments_completion
;;
wp)
case ${COMP_WORDS[2]} in
cache)
_compreply add decr delete flush get incr replace set type
;;
cap)
_compreply add list remove
;;
cli)
_compreply alias cache check-update cmd-dump completions has-command info param-dump update version
;;
comment)
_compreply approve count create delete exists generate get list meta recount spam status trash unapprove unspam untrash update
;;
config)
_compreply create delete edit get has list path set shuffle-salts
;;
core)
_compreply check-update download install is-installed multisite-install multisite-convert update update-db verify-checksums version
;;
cron)
_compreply event schedule test
;;
db)
_compreply check clean cli columns create drop export import optimize prefix query repair reset search size tables
;;
embed)
_compreply cache fetch handler provider
;;
i18n)
_compreply make-json make-pot
;;
language)
_compreply core plugin theme
;;
maintenance-mode)
_compreply activate deactivate is-active status
;;
media)
_compreply fix-orientation image-size import regenerate
;;
menu)
_compreply create delete item list location
;;
network)
_compreply meta
;;
option)
_compreply add delete get list patch pluck update
;;
package)
_compreply browse install list path uninstall update
;;
plugin)
_compreply activate deactivate delete get install uninstall is-active is-installed list path search status toggle uninstall update verify-checksums
;;
post)
_compreply create delete edit exists generate get list meta term update
;;
post-type)
_compreply get list
;;
profile)
_compreply eval eval-file hook stage
;;
rewrite)
_compreply flush list structure
;;
role)
_compreply create delete exists list reset
;;
scaffold)
_compreply block child-theme plugin plugin-tests post-type taxonomy theme-tests
;;
sidebar)
_compreply list
;;
site)
_compreply activate archive create deactivate delete empty list mature meta option private public spam switch-language unarchive unmature unspam
;;
super-admin)
_compreply add list remove
;;
taxonomy)
_compreply get list
;;
term)
_compreply create delete generate get list meta migrate recount update
;;
theme)
_compreply activate delete disable enable get install is-active is-installed list mod path search status update
;;
transient)
_compreply delete get list set type
;;
user)
_compreply add-cap add-role check-password create delete generate get import-csv list list-caps meta remove-cap remove-role reset-password session spam term unspam update
;;
widget)
_compreply add deactivate delete list move reset update
;;
esac
;;
esac
elif [ ${COMP_CWORD} -eq 4 -a ${COMP_WORDS[1]} == "wp" ]; then
case ${COMP_WORDS[2]} in
cli)
case ${COMP_WORDS[3]} in
alias)
_compreply add delete get list update
;;
cache)
_compreply clear prune
;;
esac
;;
comment)
case ${COMP_WORDS[3]} in
meta)
_compreply add delete get list patch pluck update
;;
esac
;;
cron)
case ${COMP_WORDS[3]} in
event)
_compreply delete list run schedule
;;
schedule)
_compreply list
;;
esac
;;
emebd)
case ${COMP_WORDS[3]} in
cache)
_compreply clear find trigger
;;
handler)
_compreply list
;;
provider)
_compreply list match
;;
esac
;;
language)
case ${COMP_WORDS[3]} in
core)
_compreply activate install is-installed list uninstall update
;;
plugin | theme)
_compreply install is-installed list uninstall update
;;
esac
;;
network)
case ${COMP_WORDS[3]} in
meta)
_compreply add delete get list patch pluck update
;;
esac
;;
post)
case ${COMP_WORDS[3]} in
meta)
_compreply add delete get list patch pluck update
;;
term)
_compreply add list remove set
;;
esac
;;
site)
case ${COMP_WORDS[3]} in
meta | option)
_compreply add delete get list patch pluck update
;;
esac
;;
term)
case ${COMP_WORDS[3]} in
meta)
_compreply add delete get list patch pluck update
;;
esac
;;
theme)
case ${COMP_WORDS[3]} in
mod)
_compreply get list remove set
;;
esac
;;
user)
case ${COMP_WORDS[3]} in
meta)
_compreply add delete get list patch pluck update
;;
session)
_compreply destroy list
;;
term)
_compreply add list remove set
;;
esac
;;
esac
fi
if [ ${#COMPREPLY[@]} -eq 0 ]; then
COMPREPLY=()
fi
return 0
}
_10updcoker_hosts_completion() {
if [ ${#COMP_WORDS[@]} -eq 2 ]; then
COMPREPLY=($(compgen -W "add remove" -- "${COMP_WORDS[COMP_CWORD]}"))
fi
return 0
}
complete -o default -F _10updocker_completion 10updocker
complete -o default -F _10updcoker_hosts_completion 10updocker-hosts