alias b := build
alias c := check
alias d := doc
alias f := fmt
alias l := clippy
alias r := run
alias t := test
alias w := watch

rust_backtrace := env("RUST_BACKTRACE", "1")
nightly := "nightly-2026-01-29"

default:
    @just --list

build:
    cargo build

check:
    @just fmt-check
    @just clippy
    @just doc-check
    cargo check --release

fmt-check:
    cargo +{{nightly}} fmt -- --check

fmt:
    cargo +{{nightly}} fmt

clippy:
    cargo +{{nightly}} clippy --all-targets

doc-check:
    cargo doc --no-deps

doc:
    cargo doc --open

# NOTE: tests may fail with regular `cargo test` due to use of env var to set
# pijul config dir to a temp dir. We have to use use `cargo-nextest` that runs
# tests in isolated processes.
test:
    cargo run --bin inflorescence-view-test-setup
    RUST_BACKTRACE={{rust_backtrace}} cargo nextest run

run bin="inflorescence":
    RUST_BACKTRACE={{rust_backtrace}} \
      cargo run \
      --bin "{{bin}}"

watch execute="check":
    RUST_BACKTRACE={{rust_backtrace}} \
        cargo watch \
        --clear \
        --why \
        --exec "{{execute}}"

watch_run_ui:
    @just watch "run --bin inflorescence"

# Run tests for view changes. The `kind` can be set to "compare" or "accept".
view kind="preview":
    TEST_KIND="{{kind}}" \
        cargo run --bin inflorescence-view-test-setup
    TEST_KIND="{{kind}}" \
        cargo nextest run --package inflorescence-view -- view

# Watch tests for view changes. The `kind` can be set to "compare" or "accept".
watch_view kind="preview":
    TEST_KIND="{{kind}}" \
        cargo watch \
        --exec "run --bin inflorescence-view-test-setup" \
        --exec "nextest run --package inflorescence-view -- view" \
        --ignore "screenshots" \
        --ignore "preview"

book:
    mdbook serve --open book