---
version: '3'

tasks:
  bundle:
    deps:
      - grex
      - htmlq
      - hyperfine

  catfs:
    run: once
    cmds:
      - task: install:rust
        vars:
          BIN_NAME: catfs
          PACKAGE: catfs

  clean:
    cmds:
      - rm -rf "$HOME/.cargo/registry"

  grex:
    run: once
    cmds:
      - task: install:rust
        vars:
          BIN_NAME: grex
          PACKAGE: grex

  htmlq:
    run: once
    cmds:
      - task: install:rust
        vars:
          BIN_NAME: htmlq
          PACKAGE: htmlq

  hyperfine:
    run: once
    cmds:
      - task: install:rust
        vars:
          BIN_NAME: hyperfine
          PACKAGE: hyperfine

  install:rust:
    vars:
      BIN: '{{if .BIN_NAME}}{{.BIN_NAME}}{{else}}{{.PACKAGE}}{{end}}'
    run: when_changed
    log:
      error: Failed to install Cargo crate `{{.PACKAGE}}`
      start: Installing Cargo crate `{{.PACKAGE}}`
      success: Installed Cargo crate `{{.PACKAGE}}`
    cmds:
      - task: :install:software:rust
      - |
        if [ -n "$CI" ]; then echo "*************** cargo --> {{.PACKAGE}}"; fi
      - cargo install {{.PACKAGE}}
    status:
      - type {{.BIN}} > /dev/null || [ -n "$NO_INSTALL_RUST" ]
