pluginctl/Makefile
Felipe Martin 73149001eb
Replace logging system with slog and tint for structured colored output
- Add logger.go with public Logger variable and InitLogger function
- Replace all fmt.Printf/fmt.Fprintf calls with structured Logger.Info/Logger.Error
- Initialize logger in main function for consistent access across packages
- Keep fmt.Errorf for proper error creation (standard Go practice)
- Add tint dependency for colorized terminal output with timestamps
- Convert user output to structured logging with key-value pairs
- Update info command to use structured logging for plugin details
- Update updateassets command to use structured progress logging
- Update version command to use structured logging
- Update authentication logging in client.go with structured fields
- Update enable/disable commands to use structured logging
- Remove unused fmt imports after conversion

All output now uses slog with tint for beautiful, structured, colorized logging
while maintaining proper error handling with fmt.Errorf for error creation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-09 16:51:40 +02:00

159 lines
3.9 KiB
Makefile

# pluginctl Makefile
# Based on common Go project patterns
# Build information
VERSION ?= $(shell git describe --tags --always --dirty)
COMMIT ?= $(shell git rev-parse --short HEAD)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go build variables
GO_VERSION ?= $(shell awk '/^go / {print $$2}' go.mod)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# Tool versions
GOLANGCI_LINT_VERSION ?= v1.62.2
GORELEASER_VERSION ?= v2.10.2
# Project variables
BINARY_NAME = pluginctl
MAIN_PACKAGE = ./cmd/pluginctl
DIST_DIR = dist
# Build flags
LDFLAGS = -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(BUILD_DATE)"
# Default target
.PHONY: all
all: clean lint test build
# Help target
.PHONY: help
help: ## Show this help message
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Clean build artifacts
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(DIST_DIR)
@rm -f $(BINARY_NAME)
@go clean -cache
# Install dependencies
.PHONY: deps
deps: ## Install/update dependencies
@echo "Installing dependencies..."
@go mod download
@go mod tidy
# Run tests
.PHONY: test
test: ## Run tests
@echo "Running tests..."
@go test -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
@go test -v -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Lint code
.PHONY: lint
lint: ## Run linter
@echo "Running linter..."
@golangci-lint run
# Fix linting issues
.PHONY: lint-fix
lint-fix: ## Fix linting issues
@echo "Fixing linting issues..."
@golangci-lint run --fix
# Build for all platforms using goreleaser
.PHONY: build-all
build: clean ## Build for all platforms using goreleaser
@echo "Building for all platforms using goreleaser..."
@goreleaser build --clean
# Install binary
.PHONY: install
install:
@echo "Installing $(BINARY_NAME)..."
@go install $(LDFLAGS) $(MAIN_PACKAGE)
# Run the application
.PHONY: run
run: ## Run the application
@go run $(MAIN_PACKAGE) $(ARGS)
# Format code
.PHONY: fmt
fmt: ## Format code
@echo "Formatting code..."
@go fmt ./...
# Generate code
.PHONY: generate
generate: ## Generate code
@echo "Generating code..."
@go generate ./...
# Check for updates
.PHONY: check-updates
check-updates: ## Check for dependency updates
@echo "Checking for dependency updates..."
@go list -u -m all
# Release (requires goreleaser)
.PHONY: release
release: ## Create a release
@echo "Creating release..."
@goreleaser release --clean
# Snapshot release (for testing)
.PHONY: snapshot
snapshot: ## Create a snapshot release
@echo "Creating snapshot release..."
@goreleaser release --snapshot --clean
# Development setup
.PHONY: dev-setup
dev-setup: ## Set up development environment
@echo "Setting up development environment..."
@go get -tool github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
@go get -tool github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION)
@echo "Development tools installed"
# Verify build
.PHONY: verify
verify: clean lint test build ## Verify build (clean, lint, test, build)
@echo "Build verification complete"
# Quick development build
.PHONY: dev
dev: fmt lint snapshot ## Quick development build (fmt, lint, build)
# Check changes target
.PHONY: check-changes
check-changes: lint test ## Check changes (lint, test)
# CI target
.PHONY: ci
ci: deps verify ## CI target (deps, verify)
# Print build info
.PHONY: version
version: ## Print version information
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Build Date: $(BUILD_DATE)"
@echo "Go Version: $(GO_VERSION)"
@echo "OS/Arch: $(GOOS)/$(GOARCH)"
@echo "Tool Versions:"
@echo " golangci-lint: $(GOLANGCI_LINT_VERSION)"
@echo " goreleaser: $(GORELEASER_VERSION)"