1+ # Makefile for OADP CLI
2+ #
3+ # This Makefile provides convenient targets for building, testing, and installing
4+ # the OADP CLI as a kubectl plugin.
5+
6+ # Variables
7+ BINARY_NAME = kubectl-oadp
8+ LOCAL_BINARY = oadp
9+ INSTALL_PATH = /usr/local/bin
10+ GO_FILES = $(shell find . -name '* .go' -not -path './vendor/* ')
11+
12+ # Default target
13+ .PHONY : help
14+ help : # # Show this help message
15+ @echo " OADP CLI Makefile"
16+ @echo " "
17+ @echo " Available targets:"
18+ @awk ' BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST )
19+
20+ # Build targets
21+ .PHONY : build
22+ build : # # Build the CLI binary for local development
23+ @echo " Building $( LOCAL_BINARY) for local development..."
24+ go build -o $(LOCAL_BINARY ) .
25+ @echo " ✅ Built $( LOCAL_BINARY) successfully!"
26+
27+ .PHONY : build-plugin
28+ build-plugin : # # Build the kubectl plugin binary
29+ @echo " Building $( BINARY_NAME) kubectl plugin..."
30+ go build -o $(BINARY_NAME ) .
31+ @echo " ✅ Built $( BINARY_NAME) successfully!"
32+
33+ # Installation targets
34+ .PHONY : install
35+ install : build-plugin # # Build and install the kubectl plugin (requires sudo)
36+ @echo " Installing $( BINARY_NAME) to $( INSTALL_PATH) ..."
37+ sudo mv $(BINARY_NAME ) $(INSTALL_PATH ) /
38+ @echo " ✅ $( BINARY_NAME) plugin installed successfully!"
39+ @echo " You can now use: kubectl oadp --help"
40+
41+ .PHONY : install-local
42+ install-local : build-plugin # # Install the kubectl plugin to ~/bin (no sudo required)
43+ @echo " Installing $( BINARY_NAME) to ~/bin..."
44+ @mkdir -p ~ /bin
45+ mv $(BINARY_NAME ) ~ /bin/
46+ @echo " ✅ $( BINARY_NAME) plugin installed to ~/bin!"
47+ @echo " Make sure ~/bin is in your PATH"
48+ @echo " You can now use: kubectl oadp --help"
49+
50+ # Testing targets
51+ .PHONY : test
52+ test : # # Run all tests
53+ @echo " Running tests..."
54+ go test ./...
55+ @echo " ✅ All tests passed!"
56+
57+ .PHONY : test-verbose
58+ test-verbose : # # Run tests with verbose output
59+ @echo " Running tests with verbose output..."
60+ go test -v ./...
61+
62+ .PHONY : test-coverage
63+ test-coverage : # # Run tests with coverage report
64+ @echo " Running tests with coverage..."
65+ go test -cover ./...
66+
67+ # Development targets
68+ .PHONY : fmt
69+ fmt : # # Format Go code
70+ @echo " Formatting Go code..."
71+ go fmt ./...
72+ @echo " ✅ Code formatted!"
73+
74+ .PHONY : vet
75+ vet : # # Run go vet
76+ @echo " Running go vet..."
77+ go vet ./...
78+ @echo " ✅ Vet checks passed!"
79+
80+ .PHONY : mod-tidy
81+ mod-tidy : # # Tidy up go.mod
82+ @echo " Tidying go.mod..."
83+ go mod tidy
84+ @echo " ✅ Dependencies tidied!"
85+
86+ .PHONY : check
87+ check : fmt vet test # # Run formatting, vetting, and tests
88+
89+ # Cleanup targets
90+ .PHONY : clean
91+ clean : # # Remove built binaries
92+ @echo " Cleaning up built binaries..."
93+ @rm -f $(BINARY_NAME ) $(LOCAL_BINARY )
94+ @echo " ✅ Cleanup complete!"
95+
96+ .PHONY : uninstall
97+ uninstall : # # Remove the installed kubectl plugin
98+ @echo " Removing $( BINARY_NAME) from $( INSTALL_PATH) ..."
99+ @sudo rm -f $(INSTALL_PATH ) /$(BINARY_NAME )
100+ @echo " ✅ $( BINARY_NAME) plugin uninstalled!"
101+
102+ .PHONY : uninstall-local
103+ uninstall-local : # # Remove the kubectl plugin from ~/bin
104+ @echo " Removing $( BINARY_NAME) from ~/bin..."
105+ @rm -f ~ /bin/$(BINARY_NAME )
106+ @echo " ✅ $( BINARY_NAME) plugin uninstalled from ~/bin!"
107+
108+ # Utility targets
109+ .PHONY : verify-install
110+ verify-install : # # Verify the kubectl plugin is installed and working
111+ @echo " Verifying kubectl plugin installation..."
112+ @if command -v kubectl oadp > /dev/null 2>&1 ; then \
113+ echo " ✅ kubectl oadp plugin is installed and accessible!" ; \
114+ kubectl oadp --help | head -5; \
115+ else \
116+ echo " ❌ kubectl oadp plugin not found in PATH" ; \
117+ exit 1; \
118+ fi
119+
120+ .PHONY : dev-setup
121+ dev-setup : mod-tidy fmt vet build # # Set up development environment
122+ @echo " ✅ Development environment ready!"
123+
124+ # File watching (requires 'entr' tool)
125+ .PHONY : watch
126+ watch : # # Watch for changes and rebuild (requires 'entr' tool)
127+ @if command -v entr > /dev/null 2>&1 ; then \
128+ echo " Watching for changes... (press Ctrl+C to stop)" ; \
129+ find . -name ' *.go' | entr -r make build; \
130+ else \
131+ echo " ❌ 'entr' tool not found. Install with: brew install entr (macOS) or apt install entr (Ubuntu)" ; \
132+ exit 1; \
133+ fi
134+
135+ # Show current status
136+ .PHONY : status
137+ status : # # Show build status and installed version
138+ @echo " === OADP CLI Status ==="
139+ @echo " "
140+ @echo " 📁 Repository:"
141+ @pwd
142+ @echo " "
143+ @echo " 🔧 Local binaries:"
144+ @ls -la $(LOCAL_BINARY ) $(BINARY_NAME ) 2> /dev/null || echo " No local binaries found"
145+ @echo " "
146+ @echo " 📦 Installed plugin:"
147+ @ls -la $(INSTALL_PATH ) /$(BINARY_NAME ) 2> /dev/null || echo " Plugin not installed in $( INSTALL_PATH) "
148+ @ls -la ~ /bin/$(BINARY_NAME ) 2> /dev/null || echo " Plugin not installed in ~/bin"
149+ @echo " "
150+ @echo " ✅ Plugin accessibility:"
151+ @if command -v kubectl oadp > /dev/null 2>&1 ; then \
152+ echo " kubectl oadp is accessible" ; \
153+ else \
154+ echo " kubectl oadp is NOT accessible" ; \
155+ fi
0 commit comments