-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·110 lines (85 loc) · 2.03 KB
/
run
File metadata and controls
executable file
·110 lines (85 loc) · 2.03 KB
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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
DC="${DC:-exec}"
# If we're not in a terminal, disable TTY allocation
TTY="${TTY:-}"
if [[ ! -t 1 ]]; then
TTY="-T"
fi
# -----------------------------------------------------------------------------
# Helper functions
# -----------------------------------------------------------------------------
_dc() {
# shellcheck disable=SC2086
docker compose "${DC}" ${TTY} "${@}"
}
_dc_run() {
DC="run" _dc --no-deps --rm "${@}"
}
# -----------------------------------------------------------------------------
# Commands
# -----------------------------------------------------------------------------
cmd() {
# Run any command you want in the web container
_dc web "${@}"
}
rails() {
# Run any Rails commands
cmd rails "${@}"
}
bundle() {
# Run bundle commands
cmd bundle "${@}"
}
shell() {
# Start a shell session in the web container
cmd bash "${@}"
}
psql() {
# Connect to PostgreSQL with psql
# shellcheck disable=SC1091
. .env
_dc db psql -U "${POSTGRES_USER:-medtracker}" "${@}"
}
db:setup() {
# Setup the database (create, schema load, seed)
rails db:setup
}
db:migrate() {
# Run database migrations
rails db:migrate
}
db:reset() {
# Drop, create, migrate and seed the database
rails db:reset
}
db:seed() {
# Seed the database
rails db:seed
}
test() {
# Run RSpec tests
_dc_run -e "RAILS_ENV=test" web bundle exec rspec "${@}"
}
format() {
# Format Ruby code with RuboCop
cmd rubocop -A "${@}"
}
lint() {
# Lint Ruby code with RuboCop
cmd rubocop "${@}"
}
clean() {
# Remove cache and other machine generated files
rm -rf node_modules/ public/assets tmp/* storage/* log/*
}
help() {
printf "%s <task> [args]\\n\\nTasks:\\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\\nExtended help:\\n Each task has comments for general usage\\n"
}
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
"${@:-help}"