Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 50c5f94

Browse files
committed
Command completion.
1 parent 28940b2 commit 50c5f94

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

etc/box-completion.bash

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#/usr/bin/env bash
2+
3+
################################################################################
4+
# Command completion for 'box'
5+
_box()
6+
{
7+
local cur=${COMP_WORDS[COMP_CWORD]}
8+
local prev=${COMP_WORDS[COMP_CWORD-1]}
9+
10+
11+
case "${COMP_WORDS[1]}" in
12+
'container')
13+
# /opt/box/bin/box container help
14+
_box_container
15+
return 0
16+
;;
17+
18+
'database')
19+
COMPREPLY=($(compgen -W "backup import chunk unchunk credentials dbname username password" -- $cur))
20+
return 0
21+
;;
22+
23+
'startup')
24+
COMPREPLY=($(compgen -W "" -- $cur))
25+
return 0
26+
;;
27+
28+
'restart')
29+
COMPREPLY=($(compgen -W "" -- $cur))
30+
return 0
31+
;;
32+
33+
'shutdown')
34+
COMPREPLY=($(compgen -W "" -- $cur))
35+
return 0
36+
;;
37+
38+
'status')
39+
COMPREPLY=($(compgen -W "" -- $cur))
40+
return 0
41+
;;
42+
43+
'shell')
44+
COMPREPLY=($(compgen -W "" -- $cur))
45+
return 0
46+
;;
47+
48+
'version')
49+
COMPREPLY=($(compgen -W "" -- $cur))
50+
return 0
51+
;;
52+
53+
'self-update')
54+
COMPREPLY=($(compgen -W "$(git --git-dir=/opt/box/.git tag)" -- $cur))
55+
return 0
56+
;;
57+
58+
'test')
59+
COMPREPLY=($(compgen -W "$(find /opt/box/cli/tests -maxdepth 1 -type f -printf '%f\n')" -- $cur))
60+
return 0
61+
;;
62+
63+
'help')
64+
COMPREPLY=($(compgen -W "" -- $cur))
65+
return 0
66+
;;
67+
esac
68+
69+
COMPREPLY=($(compgen -W "database container startup restart shutdown status shell version self-update test help" -- $cur))
70+
}
71+
complete -F _box box
72+
73+
74+
75+
################################################################################
76+
# Command completion for 'box container'
77+
_box_container()
78+
{
79+
local cur=${COMP_WORDS[COMP_CWORD]}
80+
local prev=${COMP_WORDS[COMP_CWORD-1]}
81+
82+
case "$prev" in
83+
'stop'|'restart')
84+
_box_container_running
85+
return 0
86+
;;
87+
88+
'start'|'restart'|'rm'|'clean'|'refresh')
89+
_box_container_stopped
90+
return 0
91+
;;
92+
93+
'ls'|'inspect'|'log')
94+
_box_container_all
95+
return 0
96+
;;
97+
98+
'pull'|'install')
99+
_box_container_dockerhub
100+
return 0
101+
;;
102+
esac
103+
104+
COMPREPLY=($(compgen -W "install ls start stop rm clean refresh update show shutdown reallyclean inspect log pull" -- $cur))
105+
return 0
106+
}
107+
108+
_box_container_running()
109+
{
110+
local cur=${COMP_WORDS[COMP_CWORD]}
111+
112+
COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib -f status=running --format='{{.Image}}')" -- $cur))
113+
return 0
114+
}
115+
116+
117+
_box_container_stopped()
118+
{
119+
local cur=${COMP_WORDS[COMP_CWORD]}
120+
121+
COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib -f status=created -f status=exited --format='{{.Image}}')" -- $cur))
122+
return 0
123+
}
124+
125+
126+
_box_container_all()
127+
{
128+
local cur=${COMP_WORDS[COMP_CWORD]}
129+
130+
COMPREPLY=($(compgen -W "$(docker container ls -af label=container.project=wplib --format='{{.Image}}')" -- $cur))
131+
return 0
132+
}
133+
134+
135+
_box_container_dockerhub()
136+
{
137+
local IMAGES
138+
local IMAGE_NAME
139+
local VERSIONS
140+
local IMAGE_VERSION
141+
local REPLY
142+
local cur=${COMP_WORDS[COMP_CWORD]}
143+
144+
IMAGES="`jq -r '.results|.[]|.name' /opt/box/etc/respositories.json`"
145+
for IMAGE_NAME in $IMAGES
146+
do
147+
VERSIONS="`jq -r '.results|.[]|.name' /opt/box/etc/images/${IMAGE_NAME}.json`"
148+
for IMAGE_VERSION in $VERSIONS
149+
do
150+
REPLY="$REPLY wplib/${IMAGE_NAME}:$IMAGE_VERSION"
151+
done
152+
153+
done
154+
155+
COMPREPLY=($(compgen -W "$REPLY" -- $cur))
156+
return 0
157+
}
158+
159+

0 commit comments

Comments
 (0)