forked from ksred/ccswitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
186 lines (165 loc) · 7.08 KB
/
Makefile
File metadata and controls
186 lines (165 loc) · 7.08 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
.PHONY: all build run install test test-unit test-integration test-docker clean help
# Variables
BINARY_NAME=ccswitch
GO_FILES=$(shell find . -name '*.go' -not -path "./vendor/*")
COVERAGE_FILE=coverage.out
# Version information
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS = -ldflags "-X github.com/ksred/ccswitch/internal/version.Version=$(VERSION) -X github.com/ksred/ccswitch/internal/version.Commit=$(COMMIT) -X github.com/ksred/ccswitch/internal/version.BuildTime=$(BUILD_TIME)"
# Default target
all: build
# Build the binary
build:
@go run internal/buildhelper/main.go info "Building $(BINARY_NAME)..."
@go build $(LDFLAGS) -o $(BINARY_NAME) .
# Run the application (interactive)
run: build
@./$(BINARY_NAME)
# Run with list command
run-list: build
@./$(BINARY_NAME) list
# Run with cleanup command
run-cleanup: build
@./$(BINARY_NAME) cleanup
# Run with switch command
run-switch: build
@./$(BINARY_NAME) switch
# Install the binary to GOPATH/bin
install: build
@go run internal/buildhelper/main.go info "Installing $(BINARY_NAME)..."
@FIRST_GOPATH=$$(go env GOPATH | cut -d':' -f1) && \
cp $(BINARY_NAME) "$$FIRST_GOPATH/bin/$(BINARY_NAME)" && \
chmod +x "$$FIRST_GOPATH/bin/$(BINARY_NAME)" && \
go run internal/buildhelper/main.go success "✓ Installed binary to $$FIRST_GOPATH/bin/$(BINARY_NAME)"
@echo ""
@# Install shell integration
@go run internal/buildhelper/main.go info "Setting up shell integration..."
@SHELL_CONFIG=""; \
SHELL_NAME=""; \
if [ -n "$$ZSH_VERSION" ] || [ "$$SHELL" = "/bin/zsh" ] || [ "$$SHELL" = "/usr/bin/zsh" ]; then \
SHELL_CONFIG="$$HOME/.zshrc"; \
SHELL_NAME="zsh"; \
elif [ -n "$$BASH_VERSION" ] || [ "$$SHELL" = "/bin/bash" ] || [ "$$SHELL" = "/usr/bin/bash" ]; then \
SHELL_CONFIG="$$HOME/.bashrc"; \
SHELL_NAME="bash"; \
fi; \
if [ -n "$$SHELL_CONFIG" ]; then \
if ! grep -q "eval \"\$$(ccswitch shell-init)\"" "$$SHELL_CONFIG" 2>/dev/null && \
! grep -q "source.*ccswitch/bash.txt" "$$SHELL_CONFIG" 2>/dev/null; then \
echo "" >> "$$SHELL_CONFIG"; \
echo "# ccswitch shell integration" >> "$$SHELL_CONFIG"; \
echo 'eval "$$(ccswitch shell-init)"' >> "$$SHELL_CONFIG"; \
go run internal/buildhelper/main.go success "✓ Added shell integration to $$SHELL_CONFIG"; \
echo ""; \
echo "To activate now, run:"; \
echo " source $$SHELL_CONFIG"; \
else \
go run internal/buildhelper/main.go success "✓ Shell integration already installed in $$SHELL_CONFIG"; \
fi; \
else \
echo ""; \
go run internal/buildhelper/main.go warning "⚠️ Could not detect shell type. To enable shell integration, add this to your shell config:"; \
echo ""; \
echo " eval \"\$$(ccswitch shell-init)\""; \
echo ""; \
echo "For example:"; \
echo " echo 'eval \"\$$(ccswitch shell-init)\"' >> ~/.bashrc"; \
echo " source ~/.bashrc"; \
fi
# Uninstall ccswitch
uninstall:
@go run internal/buildhelper/main.go info "Uninstalling $(BINARY_NAME)..."
@FIRST_GOPATH=$$(go env GOPATH | cut -d':' -f1) && \
rm -f "$$FIRST_GOPATH/bin/$(BINARY_NAME)" && \
go run internal/buildhelper/main.go success "✓ Removed binary from $$FIRST_GOPATH/bin/$(BINARY_NAME)"
@echo ""
@go run internal/buildhelper/main.go info "Removing shell integration..."
@SHELL_CONFIG=""; \
if [ -f "$$HOME/.zshrc" ]; then \
SHELL_CONFIG="$$HOME/.zshrc"; \
elif [ -f "$$HOME/.bashrc" ]; then \
SHELL_CONFIG="$$HOME/.bashrc"; \
fi; \
if [ -n "$$SHELL_CONFIG" ]; then \
if grep -q "eval \"\$$(ccswitch shell-init)\"" "$$SHELL_CONFIG" 2>/dev/null || \
grep -q "source.*ccswitch/bash.txt" "$$SHELL_CONFIG" 2>/dev/null; then \
cp "$$SHELL_CONFIG" "$$SHELL_CONFIG.bak"; \
grep -v "eval \"\$$(ccswitch shell-init)\"" "$$SHELL_CONFIG.bak" | \
grep -v "source.*ccswitch/bash.txt" | \
grep -v "# ccswitch shell integration" > "$$SHELL_CONFIG"; \
rm "$$SHELL_CONFIG.bak"; \
go run internal/buildhelper/main.go success "✓ Removed shell integration from $$SHELL_CONFIG"; \
else \
go run internal/buildhelper/main.go success "✓ No shell integration found to remove"; \
fi; \
fi
@echo ""
@go run internal/buildhelper/main.go success "Uninstall complete!"
# Run all tests
test: test-unit test-integration
# Run unit tests only (no git required)
test-unit:
@go run internal/buildhelper/main.go info "Running unit tests..."
@go test -v -run "^Test(Slugify|ParseWorktrees|SessionItem|GetCurrentDir|RunCmd|WorktreeType)" ./...
# Run integration tests (requires git)
test-integration:
@go run internal/buildhelper/main.go info "Running integration tests..."
@go test -v -run "^Test(CreateSession|ListSessions|CleanupSession|GetActiveSessions|Integration)" ./... || true
# Run tests in Docker container (for clean git environment)
test-docker:
@go run internal/buildhelper/main.go info "Building Docker test environment..."
@docker build -t ccsplit-test -f Dockerfile.test .
@go run internal/buildhelper/main.go info "Running tests in Docker..."
@docker run --rm ccsplit-test
# Generate coverage report
coverage:
@go run internal/buildhelper/main.go info "Generating coverage report..."
@go test -coverprofile=$(COVERAGE_FILE) ./...
@go tool cover -html=$(COVERAGE_FILE) -o coverage.html
@go run internal/buildhelper/main.go success "Coverage report generated at coverage.html"
# Run benchmarks
bench:
@go run internal/buildhelper/main.go info "Running benchmarks..."
@go test -bench=. -benchmem ./...
# Test the bash wrapper
test-bash:
@go run internal/buildhelper/main.go info "Testing bash wrapper..."
@bash bash_wrapper_test.sh
# Clean build artifacts
clean:
@go run internal/buildhelper/main.go info "Cleaning..."
@rm -f $(BINARY_NAME)
@rm -f $(COVERAGE_FILE)
@rm -f coverage.html
@go clean
# Format code
fmt:
@go run internal/buildhelper/main.go info "Formatting code..."
@go fmt ./...
# Run linter
lint:
@go run internal/buildhelper/main.go info "Running linter..."
@golangci-lint run || echo "Install golangci-lint: https://golangci-lint.run/usage/install/"
# Show help
help:
@echo "Available targets:"
@echo " make build - Build the binary"
@echo " make run - Build and run (create new session)"
@echo " make run-list - Build and run list command"
@echo " make run-switch - Build and run switch command"
@echo " make run-cleanup - Build and run cleanup command"
@echo " make install - Install binary and shell integration"
@echo " make uninstall - Remove binary and shell integration"
@echo " make test - Run all tests"
@echo " make test-unit - Run unit tests only"
@echo " make test-integration - Run integration tests"
@echo " make test-docker - Run tests in Docker container"
@echo " make test-bash - Test the bash wrapper"
@echo " make coverage - Generate coverage report"
@echo " make bench - Run benchmarks"
@echo " make clean - Clean build artifacts"
@echo " make fmt - Format code"
@echo " make lint - Run linter"
@echo " make help - Show this help message"