# Contributor: Alexander Sharov <kvendingoldo@gmail.com>
# Maintainer: Alexander Sharov <kvendingoldo@gmail.com>
pkgname=tenv
pkgver=3.2.4
pkgrel=2
pkgdesc="OpenTofu, Terraform, Terragrunt, and Atmos version manager"
license="Apache-2.0"
arch="all"
url="https://github.com/tofuutils/tenv"
source="tenv-$pkgver.tar.gz::https://github.com/tofuutils/tenv/archive/v$pkgver.tar.gz"
options="net"
depends="cosign !terraform !tofu !terragrunt !atmos"
makedepends="go cosign"

subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local i
	mkdir build
	for i in tenv terraform terragrunt tf tofu atmos; do
		go build -ldflags "-s -w -X main.version=v$pkgver" -o build/$i ./cmd/$i
	done

	for i in bash fish zsh; do
		./build/tenv completion $i > ./tenv.$i
	done
}

check() {
	make test
}

package() {
	install -Dm755 -t "$pkgdir"/usr/bin build/*

	install -Dm644 ./tenv.bash $pkgdir/usr/share/bash-completion/completions/tenv
	install -Dm644 ./tenv.fish $pkgdir/usr/share/fish/vendor_completions.d/tenv.fish
	install -Dm644 ./tenv.zsh $pkgdir/usr/share/zsh/site-functions/tenv
}

sha512sums="
ae1ec16358b005c499177b675835e01a95869690631cf4dab40b898d4c5d4fd54b6a8624d519c9f8b88ea83f2fe76b8f763d283f73279b14eb06b26e4188affe tenv-3.2.4.tar.gz"
