checkmy 0.1.2

Network diagnostic toolkit
# checkmy CLI task runner

# Container runtime (docker or podman)
container-cmd := env("CONTAINER_CMD", "podman")

# API container image
api-image := "ghcr.io/weareproxima/checkmy-api:latest"

# Container name for the local API
api-container := "checkmy-api"

# Local API address
api-url := "http://localhost:7701"

# Default: list available recipes
default:
    @just --list

# --- Build & Dev ---

# Build (debug)
build:
    cargo build

# Build (release)
release:
    cargo build --release

# Run a CLI command (debug build → uses localhost:7701 by default)
run *args:
    cargo run -- {{args}}

# Run a CLI command in local-only mode (no API, all lookups run locally)
run-local *args:
    CHECKMY_API_URL="" cargo run -- {{args}}

# --- Quality ---

# Auto-format code
fmt:
    cargo fmt --all

# Run clippy
lint:
    cargo clippy --all-targets -- -D warnings

# Run all tests
test:
    cargo test

# Run integration tests only
test-cli:
    cargo test --test cli

# Format, lint, test (PR check)
check:
    cargo fmt --all --check
    cargo clippy --all-targets -- -D warnings
    cargo test

# --- API (local via container) ---

# Pull the latest API image
setup-api:
    {{container-cmd}} pull {{api-image}}
    @echo ""
    @echo "Setup complete. Start the API with: just start-api"

# Start the API container (port 7701)
start-api:
    #!/usr/bin/env bash
    set -euo pipefail
    # Remove any existing container with the same name.
    {{container-cmd}} rm -f {{api-container}} 2>/dev/null || true
    echo "==> Starting {{api-container}} on {{api-url}}..."
    {{container-cmd}} run -d \
        --name {{api-container}} \
        -p 7701:3000 \
        {{api-image}}
    # Wait for the server to be ready.
    for i in $(seq 1 30); do
        if curl -fsS {{api-url}}/health >/dev/null 2>&1; then
            echo "==> API is ready at {{api-url}}"
            exit 0
        fi
        sleep 0.5
    done
    echo "Error: API failed to start within 15 seconds."
    {{container-cmd}} logs {{api-container}}
    exit 1

# Stop the API container
stop-api:
    @{{container-cmd}} stop {{api-container}} 2>/dev/null && echo "API stopped." || echo "API is not running."

# Show API container logs
logs-api:
    {{container-cmd}} logs -f {{api-container}}