name := `uv run pyproject-info project.name | xargs`
version := `uv run pyproject-info project.version | xargs`

[default]
_default:
    @just --list

# Display project info
info:
    @echo "Name: {{ name }}"
    @echo "Version: {{ version }}"

# Set up a dev environment
init-dev:
    #!/usr/bin/env zsh
    set -e

    if [ ! -d ".venv" ]; then
        uv venv
    fi
    uv tool install 'pyproject-parser[cli]'
    uv sync --all-extras

# Run QA on code
qa: init-dev lint format

# Run linters and type checkers
lint:
    uv run ruff check .
    uv run ty check .

# Format code
format:
    just --fmt
    uv run black .

# Build the library
build:
    @rm -r dist
    @uv build

# Bump the library version: https://docs.astral.sh/uv/guides/package/#updating-your-version
version-bump LEVEL:
    uv version --bump {{ LEVEL }}

# Publish a version to test.pypi.org. Usage: just publish-test $(security find-generic-password -s test.pypi.org -w)
publish-test TOKEN *ARGS:
    #!/usr/bin/env zsh
    set -e

    # Zsh syntax: variable?prompt
    read "response?Are you sure? [y/N]: "

    case "$response" in
        [yY][eE][sS]|[yY])
            echo "Publishing {{ name }}@{{ version }}..."
            uv publish --index testpypi --token {{ TOKEN }} {{ ARGS }}
            ;;
        *)
            echo "Publication canceled."
            exit 1
            ;;
    esac

# Publish a version to pypi.org. Usage: just publish-test $(security find-generic-password -s pypi.org -w)
publish-pypi TOKEN *ARGS:
    #!/usr/bin/env zsh
    set -e

    # Zsh syntax: variable?prompt
    read "response?Are you sure? [y/N]: "

    case "$response" in
        [yY][eE][sS]|[yY])
            echo "Publishing {{ name }}@{{ version }}..."
            uv publish --token {{ TOKEN }} {{ ARGS }}
            ;;
        *)
            echo "Publication canceled."
            exit 1
            ;;
    esac
