# SPDX-FileCopyrightText: 2025 Gergely Nagy
# SPDX-FileContributor: Gergely Nagy
#
# SPDX-License-Identifier: MIT

set unstable

# Display this help screen
help:
    @just --list

# Format all sources
fmt:
    treefmt --ci

# Verify that all licenses are properly declared
license-check:
    reuse lint

# Build iocaine, optionally with custom OPTIONS.
build *OPTIONS:
    cargo build {{ OPTIONS }}

# Run Clippy with a set of lints: either "default" or "pedantic".
clippy lints="default":
    @just clippy-{{ lints }}

# Update & commit a dependency. The dependency must be either "flake", "assets", "robots-json", or "fennel".
update dependency="flake" *OPTIONS:
  @just update-{{ dependency }} {{ OPTIONS }}

[private]
update-flake *OPTIONS:
  nix flake update --commit-lock-file {{ OPTIONS }}
  GIT_EDITOR=cat git commit --amend --gpg-sign

[private, script]
update-robots-json ROBOTS_VERSION="1.44":
  echo "* Updating ai.robots.txt/robots.json..."
  mkdir -p data/defaults/etc
  curl -sL --fail --fail-early "https://github.com/ai-robots-txt/ai.robots.txt/archive/refs/tags/v{{ ROBOTS_VERSION }}.tar.gz" | \
    tar --strip-components=1 --wildcards --no-wildcards-match-slash -C data/defaults/etc -xzf - '*/robots.json'

[private, script]
update-fennel FENNEL_VERSION="1.6.0":
  echo "* Updating the fennel compiler..."
  mkdir -p data/defaults/etc
  curl -sL --fail --fail-early "https://fennel-lang.org/downloads/fennel-{{ FENNEL_VERSION }}.lua" \
       -o data/defaults/etc/fennel.lua

[private]
update-assets: update-robots-json update-fennel

[private]
clippy-default *OPTS:
    cargo clippy -- {{ OPTS }}

[private]
clippy-pedantic *OPTS:
    cargo clippy -- \
          -W clippy::pedantic \
          -W clippy::nursery \
          -W clippy::str_to_string \
          -A clippy::missing_panics_doc \
          -A clippy::missing_errors_doc \
          -A clippy::module_name_repetitions \
          -A clippy::missing_const_for_fn \
          -A clippy::derive_partial_eq_without_eq \
          -D clippy::unwrap_used \
          {{ OPTS }}
