# suredata-client — common dev tasks (uv, ruff, ty, pytest)

set shell := ["bash", "-uc"]

# Show available recipes.
default:
    @just --list

# Install/sync runtime and dev dependencies.
sync:
    uv sync --all-extras

# Format Python sources in place.
format:
    uv run ruff format .

# Check formatting without writing changes.
format-check:
    uv run ruff format --check .

# Run Ruff lint checks.
lint:
    uv run ruff check .

# Run static type checks (ty).
typecheck:
    uvx ty check

# Run the test suite. Pass extra pytest args, e.g. `just test -k auth`.
test *args:
    uv run pytest {{ args }}

# Run format-check, lint, typecheck, and tests (CI-style).
check: format-check lint typecheck test

# Bump the project version in pyproject.toml (default: patch).
bump-version bump="patch":
    @set -euo pipefail; \
    case "{{ bump }}" in \
      major|minor|patch) uv_bump="{{ bump }}" ;; \
      *) echo "Usage: just bump-version [major|minor|patch]" >&2; exit 2 ;; \
    esac; \
    if ! git diff --quiet || ! git diff --cached --quiet; then \
      echo "Working tree has uncommitted changes; commit or stash them first." >&2; \
      exit 1; \
    fi; \
    version="$(uv version --bump "$uv_bump" --dry-run --short)"; \
    tag="v${version}"; \
    if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then \
      echo "Tag ${tag} already exists." >&2; \
      exit 1; \
    fi; \
    uv version --bump "$uv_bump" --no-sync; \
    git add pyproject.toml uv.lock; \
    git commit -m "Bump version to ${version}"; \
    git tag "$tag"; \
    echo "Bumped version to ${version} and created tag ${tag}."

# List CLI resources (no API key required).
cli-resources:
    uv run suredata-client resources

# Run the CLI with arbitrary args, e.g. `just run list accounts --all`.

# Requires SURE_API_KEY (and optionally SURE_BASE_URL) in the environment.
run *args:
    uv run suredata-client {{ args }}
