-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
174 lines (155 loc) · 6.35 KB
/
Copy pathMakefile
File metadata and controls
174 lines (155 loc) · 6.35 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
# Devgraph CLI Makefile
# Binary name (can be overridden)
BINARY_NAME ?= dg
INSTALL_PATH ?= ~/bin
# Detect shell and OS
# Try multiple methods to detect the actual user shell
USER_SHELL := $(shell basename "$$SHELL" 2>/dev/null || echo "")
ifeq ($(USER_SHELL),)
USER_SHELL := $(shell getent passwd $$USER 2>/dev/null | cut -d: -f7 | xargs basename)
endif
ifeq ($(USER_SHELL),sh)
# If detected as 'sh', check if it's actually bash
USER_SHELL := $(shell if [ -n "$$BASH_VERSION" ]; then echo bash; else echo sh; fi)
endif
SHELL_TYPE := $(USER_SHELL)
UNAME_S := $(shell uname -s)
.PHONY: test test-verbose test-cover build clean lint fmt help install uninstall install-completions
# Build the binary
build:
go build -o $(BINARY_NAME) .
# Install the binary and completions
install: build install-completions
install -d $(INSTALL_PATH)
install -m 755 $(BINARY_NAME) $(INSTALL_PATH)/$(BINARY_NAME)
@echo ""
@echo "✓ Installation complete!"
@echo ""
@echo "Shell completions have been installed."
@echo "Restart your shell or source the completion file to enable completions."
# Install shell completions
install-completions: build
@echo "Installing shell completions..."
ifeq ($(SHELL_TYPE),zsh)
@mkdir -p ~/.zsh/completions
@./$(BINARY_NAME) completion zsh > ~/.zsh/completions/_$(BINARY_NAME)
@echo "✓ Zsh completions installed to ~/.zsh/completions/_$(BINARY_NAME)"
@echo ""
@echo " To enable now, run:"
@echo " source ~/.zsh/completions/_$(BINARY_NAME)"
@echo ""
@echo " To enable permanently, add to your ~/.zshrc if not present:"
@echo " fpath=(~/.zsh/completions \$$fpath) && autoload -Uz compinit && compinit"
else ifeq ($(SHELL_TYPE),fish)
@mkdir -p ~/.config/fish/completions
@./$(BINARY_NAME) completion fish > ~/.config/fish/completions/$(BINARY_NAME).fish
@echo "✓ Fish completions installed to ~/.config/fish/completions/$(BINARY_NAME).fish"
@echo ""
@echo " Completions will be automatically loaded in new fish shells"
else ifeq ($(SHELL_TYPE),bash)
ifeq ($(UNAME_S),Darwin)
@if [ -d /usr/local/etc/bash_completion.d ]; then \
./$(BINARY_NAME) completion bash > /usr/local/etc/bash_completion.d/$(BINARY_NAME); \
echo "✓ Bash completions installed to /usr/local/etc/bash_completion.d/$(BINARY_NAME)"; \
echo ""; \
echo " To enable now, run:"; \
echo " source /usr/local/etc/bash_completion.d/$(BINARY_NAME)"; \
echo ""; \
echo " Ensure bash-completion is installed via Homebrew and loaded in ~/.bash_profile"; \
else \
mkdir -p ~/.local/share/bash-completion/completions; \
./$(BINARY_NAME) completion bash > ~/.local/share/bash-completion/completions/$(BINARY_NAME); \
echo "✓ Bash completions installed to ~/.local/share/bash-completion/completions/$(BINARY_NAME)"; \
echo ""; \
echo " To enable now, run:"; \
echo " source ~/.local/share/bash-completion/completions/$(BINARY_NAME)"; \
echo ""; \
echo " To enable permanently, add to your ~/.bashrc if not present:"; \
echo " for f in ~/.local/share/bash-completion/completions/*; do source \"\$$f\"; done"; \
fi
else
@mkdir -p ~/.local/share/bash-completion/completions
@./$(BINARY_NAME) completion bash > ~/.local/share/bash-completion/completions/$(BINARY_NAME)
@echo "✓ Bash completions installed to ~/.local/share/bash-completion/completions/$(BINARY_NAME)"
@echo ""
@echo " To enable now, run:"
@echo " source ~/.local/share/bash-completion/completions/$(BINARY_NAME)"
@echo ""
@echo " To enable permanently, add to your ~/.bashrc if not present:"
@echo " for f in ~/.local/share/bash-completion/completions/*; do source \"\$$f\"; done"
endif
else
@echo "⚠ Shell type '$(SHELL_TYPE)' not recognized. Attempting bash installation..."
@mkdir -p ~/.local/share/bash-completion/completions
@./$(BINARY_NAME) completion bash > ~/.local/share/bash-completion/completions/$(BINARY_NAME)
@echo "✓ Bash completions installed to ~/.local/share/bash-completion/completions/$(BINARY_NAME)"
@echo ""
@echo " To enable now, run:"
@echo " source ~/.local/share/bash-completion/completions/$(BINARY_NAME)"
@echo ""
@echo " If you use a different shell, run manually:"
@echo " ./$(BINARY_NAME) completion <bash|zsh|fish> --install"
endif
# Uninstall the binary and completions
uninstall: uninstall-completions
rm -f $(INSTALL_PATH)/$(BINARY_NAME)
# Uninstall shell completions
uninstall-completions:
@echo "Uninstalling shell completions..."
@rm -f ~/.zsh/completions/_$(BINARY_NAME)
@rm -f ~/.config/fish/completions/$(BINARY_NAME).fish
@rm -f ~/.local/share/bash-completion/completions/$(BINARY_NAME)
@rm -f /usr/local/etc/bash_completion.d/$(BINARY_NAME)
@echo "✓ Shell completions removed"
# Default target
help:
@echo "Available targets:"
@echo " test - Run all tests"
@echo " test-verbose - Run tests with verbose output"
@echo " test-cover - Run tests with coverage report"
@echo " build - Build the binary"
@echo " install - Install the binary and shell completions to $(INSTALL_PATH)"
@echo " install-completions - Install only shell completions"
@echo " uninstall - Uninstall the binary and completions from $(INSTALL_PATH)"
@echo " uninstall-completions - Uninstall only shell completions"
@echo " clean - Clean build artifacts"
@echo " lint - Run linter (requires golangci-lint)"
@echo " fmt - Format code"
@echo " security - Run security scans"
@echo " vuln-check - Check for vulnerabilities"
@echo " deps-check - Check for outdated dependencies"
# Run tests
test:
go test ./...
# Run tests with verbose output
test-verbose:
go test -v ./...
# Run tests with coverage
test-cover:
go test -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -html=coverage.out -o coverage.html
# Clean build artifacts
clean:
rm -f $(BINARY_NAME) coverage.out coverage.html
# Format code
fmt:
go fmt ./...
# Lint code (requires golangci-lint to be installed)
lint:
golangci-lint run
# Install dependencies
deps:
go mod tidy
go mod download
# Security scanning targets
security: vuln-check
@echo "Running security scans..."
# Check for known vulnerabilities
vuln-check:
@echo "Checking for vulnerabilities..."
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
# Check for outdated dependencies
deps-check:
@echo "Checking for outdated dependencies..."
go list -u -m all