# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

pkgname=just
pkgver=1.58.0
pkgrel=1
pkgdesc="A handy way to save and run project-specific commands"
arch=("x86_64")
url='https://just.systems'
msys2_repository_url='https://github.com/casey/just'
msys2_documentation_url='https://just.systems/man/en'
msys2_changelog_url='https://github.com/casey/just/blob/master/CHANGELOG.md'
msys2_references=(
  'anitya: 141393'
  'archlinux: just'
  'gentoo: dev-build/just'
  'purl: pkg:cargo/just'
)
license=("spdx:CC0-1.0")
depends=("gcc-libs")
makedepends=("rust")
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/casey/${pkgname}/archive/${pkgver}.tar.gz")
noextract=("${pkgname}-${pkgver}.tar.gz")
sha256sums=('c8a36e6e9397f2fdfcb0cc246fcdb790b52a784f3c8cabc0d8baeb031852a148')

prepare() {
  bsdtar -xf "${srcdir}/${pkgname}-${pkgver}.tar.gz" || true

  cd "${pkgname}-${pkgver}"

  cargo fetch --locked --target "${RUST_CHOST}"

  mkdir -p man completions
}

build() {
  cd "${pkgname}-${pkgver}"
  cargo build --frozen --release
  local just="cargo run --frozen --release --"
  $just --man > "man/${pkgname}.1"
}

check() {
  cd "${pkgname}-${pkgver}"
  cargo check --frozen --release
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm755 -t "${pkgdir}/usr/bin/" "target/release/${pkgname}"
  install -Dm644 -t "${pkgdir}/usr/share/man/man1/" "man/${pkgname}.1"
  install -Dm644 -t "${pkgdir}/usr/share/licenses/${pkgname}/" "LICENSE"
  install -Dm644 "completions/${pkgname}.bash" "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"
  install -Dm644 "completions/${pkgname}.elvish" "${pkgdir}/usr/share/elvish/lib/${pkgname}.elv"
  install -Dm644 -t "${pkgdir}/usr/share/fish/vendor_completions.d/" "completions/${pkgname}.fish"
  install -Dm644 "completions/${pkgname}.zsh" "${pkgdir}/usr/share/zsh/site-functions/_${pkgname}"
}
