Skip to content

Commit 71bb856

Browse files
committed
Help text and makefile
1 parent ae2f564 commit 71bb856

File tree

3 files changed

+166
-11
lines changed

3 files changed

+166
-11
lines changed

Makefile

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
BINARY_NAME = kubectl-oadp
7-
INSTALL_PATH ?= /usr/local/bin
7+
INSTALL_PATH ?= $(HOME)/.local/bin
88
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
99

1010
# Centralized platform definitions to avoid duplication
@@ -30,6 +30,17 @@ help: ## Show this help message
3030
@echo "Available targets:"
3131
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
3232
@echo ""
33+
@echo "Installation options:"
34+
@echo " \033[36mmake install\033[0m # Install to ~/.local/bin (recommended, no sudo)"
35+
@echo " \033[36mmake install-user\033[0m # Same as install (legacy alias)"
36+
@echo " \033[36mmake install-bin\033[0m # Install to ~/bin (alternative, no sudo)"
37+
@echo " \033[36mmake install-system\033[0m # Install to /usr/local/bin (requires sudo)"
38+
@echo ""
39+
@echo "Uninstall options:"
40+
@echo " \033[36mmake uninstall\033[0m # Remove from user locations (no sudo)"
41+
@echo " \033[36mmake uninstall-system\033[0m # Remove from system locations (requires sudo)"
42+
@echo " \033[36mmake uninstall-all\033[0m # Remove from all locations (user + system)"
43+
@echo ""
3344
@echo "Build with different platforms:"
3445
@echo " make build PLATFORM=linux/amd64"
3546
@echo " make build PLATFORM=linux/arm64"
@@ -59,11 +70,116 @@ build: ## Build the kubectl plugin binary (use PLATFORM=os/arch for cross-compil
5970

6071
# Installation targets
6172
.PHONY: install
62-
install: build ## Build and install the kubectl plugin
73+
install: build ## Build and install the kubectl plugin to ~/.local/bin (no sudo required)
6374
@echo "Installing $(BINARY_NAME) to $(INSTALL_PATH)..."
64-
mv $(BINARY_NAME) $(INSTALL_PATH)/
65-
@echo "$(BINARY_NAME) installed successfully!"
66-
@echo "You can now use: kubectl oadp --help"
75+
@mkdir -p $(INSTALL_PATH)
76+
cp $(BINARY_NAME) $(INSTALL_PATH)/
77+
@echo "✅ Installed to $(INSTALL_PATH)"
78+
@echo ""
79+
@PATH_UPDATED=false; \
80+
PATH_IN_CONFIG=false; \
81+
if [[ ":$$PATH:" != *":$(INSTALL_PATH):"* ]]; then \
82+
if [[ "$$SHELL" == */zsh* ]] && [[ -f "$$HOME/.zshrc" ]]; then \
83+
if ! grep -q "/.local/bin" "$$HOME/.zshrc" 2>/dev/null; then \
84+
echo 'export PATH="$$HOME/.local/bin:$$PATH"' >> "$$HOME/.zshrc"; \
85+
echo "✅ Added to ~/.zshrc"; \
86+
PATH_UPDATED=true; \
87+
else \
88+
echo "ℹ️ Already configured in ~/.zshrc"; \
89+
PATH_IN_CONFIG=true; \
90+
fi; \
91+
elif [[ "$$SHELL" == */bash* ]] && [[ -f "$$HOME/.bashrc" ]]; then \
92+
if ! grep -q "/.local/bin" "$$HOME/.bashrc" 2>/dev/null; then \
93+
echo 'export PATH="$$HOME/.local/bin:$$PATH"' >> "$$HOME/.bashrc"; \
94+
echo "✅ Added to ~/.bashrc"; \
95+
PATH_UPDATED=true; \
96+
else \
97+
echo "ℹ️ Already configured in ~/.bashrc"; \
98+
PATH_IN_CONFIG=true; \
99+
fi; \
100+
else \
101+
echo "⚠️ Add to your shell config: export PATH=\"$(INSTALL_PATH):$$PATH\""; \
102+
PATH_UPDATED=true; \
103+
fi; \
104+
else \
105+
echo "✅ PATH already configured"; \
106+
fi; \
107+
echo ""; \
108+
if [[ "$$PATH_UPDATED" == "true" ]] || [[ "$$PATH_IN_CONFIG" == "true" ]]; then \
109+
echo "🔄 Restart terminal or run: source ~/.zshrc"; \
110+
fi; \
111+
echo "Test: kubectl oadp --help"
112+
113+
.PHONY: install-user
114+
install-user: build ## Build and install the kubectl plugin to ~/.local/bin (no sudo required)
115+
@echo "Installing $(BINARY_NAME) to ~/.local/bin..."
116+
@mkdir -p ~/.local/bin
117+
cp $(BINARY_NAME) ~/.local/bin/
118+
@echo "✅ Installed to ~/.local/bin"
119+
@echo "Add to PATH: export PATH=\"\$$HOME/.local/bin:\$$PATH\""
120+
@echo "Test: kubectl oadp --help"
121+
122+
.PHONY: install-bin
123+
install-bin: build ## Build and install the kubectl plugin to ~/bin (no sudo required)
124+
@echo "Installing $(BINARY_NAME) to ~/bin..."
125+
@mkdir -p ~/bin
126+
cp $(BINARY_NAME) ~/bin/
127+
@echo "✅ Installed to ~/bin"
128+
@echo "Add to PATH: export PATH=\"\$$HOME/bin:\$$PATH\""
129+
@echo "Test: kubectl oadp --help"
130+
131+
.PHONY: install-system
132+
install-system: build ## Build and install the kubectl plugin to /usr/local/bin (requires sudo)
133+
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
134+
@sudo mv $(BINARY_NAME) /usr/local/bin/
135+
@echo "✅ Installed to /usr/local/bin"
136+
@echo "Test: kubectl oadp --help"
137+
138+
.PHONY: uninstall
139+
uninstall: ## Uninstall the kubectl plugin from user locations
140+
@echo "Removing $(BINARY_NAME) from user locations..."
141+
@removed=false; \
142+
if [ -f "$(INSTALL_PATH)/$(BINARY_NAME)" ]; then \
143+
rm -f "$(INSTALL_PATH)/$(BINARY_NAME)"; \
144+
echo "✅ Removed from $(INSTALL_PATH)"; \
145+
removed=true; \
146+
fi; \
147+
if [ -f "$$HOME/.local/bin/$(BINARY_NAME)" ] && [ "$(INSTALL_PATH)" != "$$HOME/.local/bin" ]; then \
148+
rm -f "$$HOME/.local/bin/$(BINARY_NAME)"; \
149+
echo "✅ Removed from ~/.local/bin"; \
150+
removed=true; \
151+
fi; \
152+
if [ -f "$$HOME/bin/$(BINARY_NAME)" ] && [ "$(INSTALL_PATH)" != "$$HOME/bin" ]; then \
153+
rm -f "$$HOME/bin/$(BINARY_NAME)"; \
154+
echo "✅ Removed from ~/bin"; \
155+
removed=true; \
156+
fi; \
157+
if [ "$$removed" = "false" ]; then \
158+
echo "⚠️ Not found in user locations"; \
159+
fi
160+
161+
.PHONY: uninstall-system
162+
uninstall-system: ## Uninstall the kubectl plugin from system locations (requires sudo)
163+
@echo "Removing $(BINARY_NAME) from system locations..."
164+
@removed=false; \
165+
if [ -f "/usr/local/bin/$(BINARY_NAME)" ]; then \
166+
sudo rm -f "/usr/local/bin/$(BINARY_NAME)"; \
167+
echo "✅ Removed from /usr/local/bin"; \
168+
removed=true; \
169+
fi; \
170+
if [ -f "/usr/bin/$(BINARY_NAME)" ]; then \
171+
sudo rm -f "/usr/bin/$(BINARY_NAME)"; \
172+
echo "✅ Removed from /usr/bin"; \
173+
removed=true; \
174+
fi; \
175+
if [ "$$removed" = "false" ]; then \
176+
echo "⚠️ Not found in system locations"; \
177+
fi
178+
179+
.PHONY: uninstall-all
180+
uninstall-all: ## Uninstall the kubectl plugin from all locations (user + system)
181+
@make --no-print-directory uninstall
182+
@make --no-print-directory uninstall-system
67183

68184
# Testing targets
69185
.PHONY: test

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,22 @@ kubectl oadp --help
4646
### Manual Build and Install
4747

4848
```sh
49-
# Build and install directly
49+
# Recommended: Rootless install (no sudo required)
5050
make install
5151

52-
# Or build manually
53-
make build
54-
sudo mv kubectl-oadp /usr/local/bin/
52+
# After install, refresh your terminal:
53+
source ~/.zshrc # or ~/.bashrc
54+
# OR restart your terminal
55+
56+
# Test the installation
57+
kubectl oadp --help
58+
59+
# Alternative: System-wide install (requires sudo)
60+
make install-system
5561
```
5662

63+
**💡 Important:** After installation, you may need to refresh your terminal or run `source ~/.zshrc` (or `~/.bashrc`) for the `kubectl oadp` command to work.
64+
5765
## Usage Guide
5866

5967
### Non-Admin Backup Operations

cmd/root.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,48 @@ func NewVeleroRootCommand() *cobra.Command {
6767
// This factory uses the current kubeconfig context namespace instead of hardcoded openshift-adp
6868
nonAdminFactory := nonadmin.NewNonAdminFactory()
6969

70+
// Create the commands and modify their help text before adding them
71+
backupCmd := backup.NewCommand(veleroFactory)
72+
restoreCmd := restore.NewCommand(veleroFactory)
73+
74+
// Modify help text to replace "velero" with "oadp"
75+
updateCommandHelpText(backupCmd, usagePrefix)
76+
updateCommandHelpText(restoreCmd, usagePrefix)
77+
7078
// Add subcommands to the root command
7179
rootCmd.AddCommand(version.NewCommand(veleroFactory))
72-
rootCmd.AddCommand(backup.NewCommand(veleroFactory))
73-
rootCmd.AddCommand(restore.NewCommand(veleroFactory))
80+
rootCmd.AddCommand(backupCmd)
81+
rootCmd.AddCommand(restoreCmd)
7482

7583
// Custom subcommands - use NonAdmin factory
7684
rootCmd.AddCommand(nonadmin.NewNonAdminCommand(nonAdminFactory))
7785

7886
return rootCmd
7987
}
8088

89+
// updateCommandHelpText recursively updates help text in commands and subcommands
90+
func updateCommandHelpText(cmd *cobra.Command, usagePrefix string) {
91+
// Update examples that contain "velero"
92+
if strings.Contains(cmd.Example, "velero") {
93+
cmd.Example = strings.ReplaceAll(cmd.Example, "velero", usagePrefix)
94+
}
95+
96+
// Update long description if it contains "velero"
97+
if strings.Contains(cmd.Long, "velero") {
98+
cmd.Long = strings.ReplaceAll(cmd.Long, "velero", "oadp")
99+
}
100+
101+
// Update short description if it contains "velero"
102+
if strings.Contains(cmd.Short, "velero") {
103+
cmd.Short = strings.ReplaceAll(cmd.Short, "velero", "oadp")
104+
}
105+
106+
// Recursively update subcommands
107+
for _, subCmd := range cmd.Commands() {
108+
updateCommandHelpText(subCmd, usagePrefix)
109+
}
110+
}
111+
81112
func Execute() {
82113
if err := NewVeleroRootCommand().Execute(); err != nil {
83114
fmt.Fprintf(os.Stderr, "Error: %v\n", err)

0 commit comments

Comments
 (0)