# -- General
SHELL := /bin/bash

# ==============================================================================
# RULES

default: help

docs/user-guide/commands.md:
	uv run python scripts/gen-cli-docs.py

# -- Build
bootstrap: ## bootstrap the project for development
bootstrap: \
  build
.PHONY: bootstrap

build: ## install project
	uv sync --locked --all-extras --dev
.PHONY: build

cmd-docs: ## Make command docs 
	$(MAKE) -B docs/user-guide/commands.md

docs-serve: ## run documentation server 
docs-serve: docs/user-guide/commands.md
	uv run mkdocs serve -w docs
.PHONY: docs-serve

docs-publish: ## publish documentation
	uv run mkdocs gh-deploy --force
.PHONY: docs-publish

# -- Quality
lint: ## lint all sources
lint: \
  lint-format \
  lint-ruff \
  lint-codespell \
  lint-markdown
.PHONY: lint

lint-format: ## format python sources with ruff format
	@echo 'lint:format started…'
	uv run ruff format watson tests scripts
.PHONY: lint-format

lint-format-check: ## check python sources formatting with ruff format
	@echo 'lint:format check started…'
	uv run ruff format --check watson tests scripts
.PHONY: lint-format-check

lint-ruff: ## lint python sources with ruff
	@echo 'lint:ruff started…'
	uv run ruff check watson tests scripts
.PHONY: lint-ruff

lint-ruff-fix: ## lint and fix python sources with ruff
	@echo 'lint:ruff-fix started…'
	uv run ruff check --fix watson tests scripts
.PHONY: lint-ruff-fix

lint-codespell: ## check spelling with codespell
	@echo 'lint:codespell started…'
	uv run codespell
.PHONY: lint-codespell

lint-codespell-fix: ## check and fix spelling with codespell
	@echo 'lint:codespell-fix started…'
	uv run codespell --write-changes
.PHONY: lint-codespell-fix

lint-markdown: ## lint markdown sources with rumdl
	@echo 'lint:markdown started…'
	uv run rumdl check .
.PHONY: lint-markdown

lint-markdown-fix: ## lint and fix markdown sources with rumdl
	@echo 'lint:markdown-fix started…'
	uv run rumdl check --fix .
.PHONY: lint-markdown-fix

test: ## run tests
	uv run pytest --cov --cov-report=term-missing --cov-report=html
.PHONY: test

completion-scripts:
	scripts/create-completion-script.sh bash
	scripts/create-completion-script.sh zsh
.PHONY: completion-scripts

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