# click-clop — Framework and scaffold for Python CLI applications
# This is click-clop's own Makefile (the framework project itself).

CONTAINER_RUNTIME ?= $(shell command -v podman 2>/dev/null || echo docker)
IMAGE_NAME ?= click-clop
IMAGE_TAG ?= latest
PYTEST ?= uv run pytest
BEHAVE ?= uv run behave

.DEFAULT_GOAL := help

.PHONY: help
help: ## Show this help message
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
		awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

# ── Python / uv ──────────────────────────────────────────────

.PHONY: install
install: ## Install project dependencies
	uv sync

.PHONY: install-dev
install-dev: ## Install with dev dependencies
	uv sync --all-extras

.PHONY: lint
lint: ## Run linting (ruff + mypy)
	uv run ruff check src/ tests/
	uv run mypy src/

.PHONY: format
format: ## Format code with ruff
	uv run ruff format src/ tests/
	uv run ruff check --fix src/ tests/

.PHONY: test
test: ## Run all tests
	$(PYTEST) tests/ -v

.PHONY: test-unit
test-unit: ## Run unit tests only
	$(PYTEST) tests/unit -v

.PHONY: test-bdd
test-bdd: ## Run BDD/Gherkin feature tests
	$(BEHAVE) features/

.PHONY: test-all
test-all: test test-bdd ## Run unit + BDD tests

.PHONY: coverage
coverage: ## Generate test coverage report
	$(PYTEST) tests/ --cov=src/click_clop --cov-report=html --cov-report=term

# ── Container ────────────────────────────────────────────────

.PHONY: build-image
build-image: ## Build container image
	$(CONTAINER_RUNTIME) build -t $(IMAGE_NAME):$(IMAGE_TAG) .

# ── Cleanup ──────────────────────────────────────────────────

.PHONY: clean
clean: ## Clean build artifacts
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name .pytest_cache -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name .mypy_cache -exec rm -rf {} + 2>/dev/null || true
	rm -rf build/ dist/ *.egg-info .coverage htmlcov/

.PHONY: build
build: clean ## Build distribution package
	uv build
