-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev
More file actions
executable file
·241 lines (220 loc) · 6.8 KB
/
dev
File metadata and controls
executable file
·241 lines (220 loc) · 6.8 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
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
#!/usr/bin/env bash
set -euo pipefail
# dev — SeaPortal developer toolkit
# Usage: dev [command] Run a command directly
# dev Interactive picker
cd "$(dirname "$0")"
BOLD=$'\033[1m'
ACCENT=$'\033[38;2;251;191;36m'
MUTED=$'\033[38;2;90;100;128m'
SUCCESS=$'\033[38;2;0;229;204m'
ERROR=$'\033[38;2;230;57;70m'
NC=$'\033[0m'
# ── Commands ─────────────────────────────────────────────────────────
COMMANDS=(
"build:🚀:Build binary"
"run:🏃:Build & run with test URL"
"check:🧪:All checks (format, vet, lint, test)"
"test:🔬:Run tests"
"test race:🏁:Run tests with race detector"
"coverage:📊:Run tests with coverage"
"lint:🔍:Run golangci-lint"
"fmt:✨:Format code"
"vet:🩺:Run go vet"
"fuzz:🎲:Run fuzz tests (30s)"
"benchmark:⚡:Run benchmarks"
"doctor:🏥:Check dev environment"
"e2e:🐳:E2E tests (Docker)"
)
# ── Helpers ──────────────────────────────────────────────────────────
show_help() {
echo ""
echo " ${ACCENT}${BOLD}🌊 SeaPortal Dev${NC}"
echo ""
for cmd in "${COMMANDS[@]}"; do
IFS=':' read -r name emoji desc <<< "$cmd"
printf " ${SUCCESS}%s${NC} ${BOLD}%-12s${NC} ${MUTED}%s${NC}\n" "$emoji" "$name" "$desc"
done
echo ""
echo " ${MUTED}Usage: ./dev [command]${NC}"
echo ""
}
run_command() {
local target="$1"
echo ""
case "$target" in
"build")
echo " ${ACCENT}${BOLD}🚀 Building seaportal${NC}"
echo ""
go build -o seaportal ./cmd/seaportal
echo " ${SUCCESS}✓${NC} Built: ./seaportal"
;;
"run")
echo " ${ACCENT}${BOLD}🏃 Build & run${NC}"
echo ""
go build -o seaportal ./cmd/seaportal
./seaportal --json https://pinchtab.com | head -30
;;
"check")
echo " ${ACCENT}${BOLD}🧪 Running checks${NC}"
echo ""
exec bash scripts/check.sh
;;
"test")
echo " ${ACCENT}${BOLD}🔬 Running tests${NC}"
echo ""
shift_args="${2:-}"
if [ "$shift_args" = "race" ]; then
go test ./... -count=1 -race -v
else
exec bash scripts/test.sh
fi
;;
"test race")
echo " ${ACCENT}${BOLD}🏁 Tests with race detector${NC}"
echo ""
go test ./... -count=1 -race -v
;;
"coverage")
echo " ${ACCENT}${BOLD}📊 Coverage${NC}"
echo ""
go test ./... -count=1 -coverprofile=coverage.out -covermode=atomic
go tool cover -func=coverage.out | tail -1
echo ""
echo " ${MUTED}Full report: go tool cover -html=coverage.out${NC}"
;;
"lint")
echo " ${ACCENT}${BOLD}🔍 Linting${NC}"
echo ""
if command -v golangci-lint &>/dev/null; then
golangci-lint run ./...
echo " ${SUCCESS}✓${NC} golangci-lint"
else
echo " ${ERROR}✗ golangci-lint not installed${NC}"
echo " ${MUTED}Install: brew install golangci-lint${NC}"
exit 1
fi
;;
"fmt")
echo " ${ACCENT}${BOLD}✨ Formatting${NC}"
echo ""
gofmt -w .
echo " ${SUCCESS}✓${NC} gofmt"
;;
"vet")
echo " ${ACCENT}${BOLD}🩺 Vet${NC}"
echo ""
go vet ./...
echo " ${SUCCESS}✓${NC} go vet"
;;
"fuzz")
echo " ${ACCENT}${BOLD}🎲 Fuzz tests${NC}"
echo ""
FUZZTIME="${2:-30s}"
echo " ${MUTED}Duration: $FUZZTIME${NC}"
echo ""
for f in $(grep -rl 'func Fuzz' --include='*_test.go' . 2>/dev/null | head -20); do
pkg=$(dirname "$f")
for fn in $(grep -oP 'func \KFuzz\w+' "$f"); do
echo " Running $fn in $pkg..."
go test "$pkg" -fuzz="$fn" -fuzztime="$FUZZTIME"
done
done
echo ""
echo " ${SUCCESS}✓${NC} Fuzz complete"
;;
"benchmark")
echo " ${ACCENT}${BOLD}⚡ Benchmarks${NC}"
echo ""
if [ -d benchmark ]; then
go test ./benchmark/ -bench=. -benchmem -count=1
else
echo " ${MUTED}No benchmark/ directory found${NC}"
fi
;;
"doctor")
echo " ${ACCENT}${BOLD}🏥 Doctor${NC}"
echo ""
exec bash scripts/doctor.sh
;;
"e2e")
echo " ${ACCENT}${BOLD}🐳 E2E tests (Docker)${NC}"
echo ""
# Check for docker compose
COMPOSE_CMD=""
if docker compose version &>/dev/null; then
COMPOSE_CMD="docker compose"
elif command -v docker-compose &>/dev/null; then
COMPOSE_CMD="docker-compose"
else
echo " ${ERROR}✗ Docker Compose not found${NC}"
echo ""
echo " Install with: brew install docker-compose"
echo " Or enable Docker Compose plugin in Docker Desktop"
exit 1
fi
echo "Building binary for Linux..."
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o tests/e2e/runner/seaportal ./cmd/seaportal
echo ""
exec $COMPOSE_CMD -f tests/e2e/docker-compose.yml up --build --abort-on-container-exit --exit-code-from runner
;;
*)
echo " ${ERROR}Unknown command: $target${NC}"
show_help
exit 1
;;
esac
}
pick_with_gum() {
local options=()
for cmd in "${COMMANDS[@]}"; do
IFS=':' read -r name emoji desc <<< "$cmd"
options+=("$(printf '%s %-12s %s' "$emoji" "$name" "$desc")")
done
local choice
choice=$(printf '%s\n' "${options[@]}" | gum choose \
--header "🌊 SeaPortal Dev" \
--header.foreground "#fbbf24" \
--cursor.foreground "#00e5cc" \
--selected.foreground "#00e5cc" \
--item.foreground "#8892b0")
local picked
picked=$(echo "$choice" | awk '{print $2}')
printf '\033[2J\033[H'
run_command "$picked"
}
pick_with_select() {
echo ""
echo " ${ACCENT}${BOLD}🌊 SeaPortal Dev${NC}"
echo ""
local names=()
local i=1
for cmd in "${COMMANDS[@]}"; do
IFS=':' read -r name emoji desc <<< "$cmd"
printf " ${MUTED}[%d]${NC} ${SUCCESS}%s${NC} ${BOLD}%-12s${NC} ${MUTED}%s${NC}\n" "$i" "$emoji" "$name" "$desc"
names+=("$name")
i=$((i + 1))
done
echo ""
echo -ne " ${BOLD}Pick [1-${#COMMANDS[@]}]:${NC} "
read -r choice
if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#COMMANDS[@]} ]; then
run_command "${names[$((choice - 1))]}"
else
run_command "$choice"
fi
}
# ── Main ─────────────────────────────────────────────────────────────
if [ $# -gt 0 ]; then
case "$1" in
-h|--help|help) show_help; exit 0 ;;
*) run_command "$1" ;;
esac
exit 0
fi
# No args → interactive picker
if command -v gum &>/dev/null; then
pick_with_gum
else
pick_with_select
fi