-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev
executable file
·95 lines (81 loc) · 1.99 KB
/
dev
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
#!/bin/bash
# Helper script for commands related to the Development Stack repository.
set -e
ERROR='\033[0;31m'
SUCCESS='\033[0;32m'
CODE='\033[0;36m'
NC='\033[0m' # No Color
cmd_helps=()
defhelp() {
local command="${1?}"
local text="${2?}"
local help_str
help_str="$(printf ' %-28s %s' "$command" "$text")"
cmd_helps+=("$help_str")
}
# Print out help information
cmd_help() {
echo "Script for performing tasks related to the Development Stack repository."
echo
echo "Usage: ./dev [COMMAND]"
echo "Replace [COMMAND] with a word from the list below."
echo
echo "COMMAND list:"
for str in "${cmd_helps[@]}"; do
echo -e "$str"
done
}
defhelp help 'View all help.'
# Start development environment
cmd_start() {
echo "Creating systems..."
docker compose -f docker-compose.yml up -d
# Alert user that system is ready
echo -e "\n${SUCCESS}System is up!${NC}"
}
defhelp start 'Start development environment.'
# Stop development environment
cmd_end() {
echo "Stopping systems..."
docker compose -f docker-compose.yml down
}
defhelp end 'Stop development environment.'
cmd_stop() {
cmd_end
}
defhelp stop 'Stop development environment. Synonym for "end".'
cmd_restart() {
docker compose -f docker-compose.yml restart "$@"
}
defhelp restart 'Restart containers.'
# Run exec
cmd_exec() {
docker compose -f docker-compose.yml exec "$@"
}
defhelp exec "Execute command in given container."
# View Docker logs
cmd_logs() {
echo "Showing Docker logs..."
docker compose -f docker-compose.yml logs --timestamps "$@"
}
defhelp logs 'View logs.'
# --- Core script logic -------------------------------------------------------
silent() {
"$@" > /dev/null 2>&1
}
# If no command given
if [ $# -eq 0 ]; then
echo -e "${ERROR}ERROR: This script requires a command!${NC}"
cmd_help
exit 1
fi
cmd="$1"
shift
if silent type "cmd_$cmd"; then
"cmd_$cmd" "$@"
exit $?
else
echo -e "${ERROR}ERROR: Unknown command!${NC}"
echo "Type './dev help' for available commands."
exit 1
fi