# AWIP Tools Makefile

.PHONY: help install test lint format build clean release release-dry release-test version version-set version-bump version-sync version-check changelog changelog-add

# 默认目标
help:
	@echo "AWIP Tools 开发命令"
	@echo ""
	@echo "安装:"
	@echo "  make install          安装开发依赖"
	@echo "  make install-prod    安装生产依赖"
	@echo ""
	@echo "开发:"
	@echo "  make test            运行测试"
	@echo "  make test-cov        运行测试并生成覆盖率报告"
	@echo "  make lint            代码检查"
	@echo "  make format          代码格式化"
	@echo ""
	@echo "构建:"
	@echo "  make build           构建发布包"
	@echo "  make clean           清理构建产物"
	@echo ""
	@echo "版本管理:"
	@echo "  make version                   显示当前版本"
	@echo "  make version-set VERSION=x.y.z 设置版本号"
	@echo "  make version-bump TYPE=patch   升级版本号"
	@echo "  make version-sync              同步所有文件版本"
	@echo "  make version-check             检查版本一致性"
	@echo ""
	@echo "变更日志:"
	@echo "  make changelog                 显示变更日志"
	@echo "  make changelog-add             添加新的变更日志条目"
	@echo ""
	@echo "发布:"
	@echo "  make release                         发布当前版本"
	@echo "  make release VERSION=patch           升级 patch 版本并发布"
	@echo "  make release VERSION=0.2.0           发布指定版本"
	@echo "  make release-dry                     模拟发布当前版本"
	@echo "  make release-test                    发布到 TestPyPI"
	@echo ""
	@echo "内部命令:"
	@echo "  make dev             以开发模式运行 CLI"
	@echo "  make internal        启用内部命令"

# 安装开发依赖
install:
	pip install -e ".[dev]"

# 安装生产依赖
install-prod:
	pip install -e .

# 运行测试
test:
	pytest tests/ -v

# 运行测试并生成覆盖率报告
test-cov:
	pytest tests/ -v --cov=src/awip --cov-report=html
	@echo "覆盖率报告: htmlcov/index.html"

# 代码检查
lint:
	ruff check src/ tests/
	black --check src/ tests/

# 代码格式化
format:
	black src/ tests/
	ruff format src/ tests/

# 构建发布包
build: clean
	hatch build
	@echo "构建产物:"
	@ls -lh dist/

# 清理构建产物
clean:
	rm -rf dist/ build/ *.egg-info src/*.egg-info htmlcov/ .coverage

# 显示当前版本
version:
	./scripts/version.sh show

# 设置版本号
version-set:
	@if [ -z "$(VERSION)" ]; then \
		echo "错误: 请指定版本号"; \
		echo "用法: make version-set VERSION=x.y.z"; \
		exit 1; \
	fi
	./scripts/version.sh set $(VERSION)

# 升级版本号
version-bump:
	@if [ -z "$(TYPE)" ]; then \
		echo "错误: 请指定升级类型"; \
		echo "用法: make version-bump TYPE=patch"; \
		exit 1; \
	fi
	./scripts/version.sh bump $(TYPE)

# 同步所有文件版本
version-sync:
	./scripts/version.sh sync

# 检查版本一致性
version-check:
	./scripts/version.sh check

# 显示变更日志
changelog:
	./scripts/version.sh changelog

# 添加变更日志条目
changelog-add:
	./scripts/version.sh changelog-add

# 发布到 PyPI
release:
	./scripts/release.sh $(VERSION)

# 模拟发布
release-dry:
	./scripts/release.sh $(VERSION) --dry-run

# 发布到 TestPyPI
release-test:
	./scripts/release.sh $(VERSION) --test

# 以开发模式运行 CLI
dev:
	AWIP_INTERNAL=1 awip

# 启用内部命令（设置环境变量）
internal:
	@echo "export AWIP_INTERNAL=1"
	@echo "或运行: AWIP_INTERNAL=1 awip <command>"