-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevtool.sh
executable file
·83 lines (71 loc) · 1.49 KB
/
devtool.sh
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
#!/usr/bin/env bash
set -e
cd "$(dirname $0)"
function build_and_run () {
./build.sh build-image
rm -rf logs
docker-compose -f docker/dev/docker-compose.yml up --force-recreate zipper
}
function start_deps () {
docker-compose -f docker/dev/docker-compose.yml up -d redis
}
# add new cmd entry here
cmds=( \
build-and-run \
start-deps \
)
function do_command () {
case $1 in
start-deps)
start_deps
;;
build-and-run)
build_and_run
;;
*)
echo "Please select what you want to do:"
;;
esac
}
# functional codes for this shell, you can ignore
function select_cmd () {
echo "Please select what you want to do:"
select CMD in ${cmds[*]}; do
if [[ $(in_array $CMD ${cmds[*]}) = 0 ]]; then
do_command $CMD
break
fi
done
}
function select_arg () {
cmd=$1
shift 1
options=("$@")
echo "Please select which arg you want:"
select ARG in ${options[*]}; do
if [[ $(in_array ${ARG} ${options[*]}) = 0 ]]; then
${cmd} ${ARG}
break
fi
done
}
function in_array () {
TARGET=$1
shift 1
for ELEMENT in $*; do
if [[ "$TARGET" == "$ELEMENT" ]]; then
echo 0
return 0
fi
done
echo 1
return 1
}
function main () {
if [[ $1 != "" && $(in_array $1 ${cmds[*]}) = 0 ]]; then
do_command $*
else
select_cmd
fi
}
main $*