maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=cue-cli
pkgver=0.11.1
pkgrel=5
pkgdesc="CLI for CUE configuration and validation language"
url="https://cuelang.org/"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
options="net" # download Go modules
source="$pkgname-$pkgver.tar.gz::https://github.com/cue-lang/cue/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/cue-$pkgver"

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

build() {
	go build -v -o bin/cue \
		-ldflags "-X cuelang.org/go/cmd/cue/cmd.version=v$pkgver" \
		./cmd/cue/

	for shell in bash fish zsh; do
		./bin/cue completion $shell > cue.$shell
	done
}

check() {
	# Use a directory outside aports repository for test artifacts to pass TestScript test case.
	# (the test expects `git VCS not found in any parents of ".+"` message in stderr)
	unset GOTMPDIR

	go test ./...
}

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

	install -Dm644 cue.bash \
		"$pkgdir"/usr/share/bash-completion/completions/cue
	install -Dm644 cue.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/cue.fish
	install -Dm644 cue.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_cue
}

sha512sums="
61e49d59e2fc0cc542dcfc273cc5fb0c9f18a0e0938a31bcf88dbb6db8b799c0b8846e1257049adcbcad172fcfdf95ae67356d1b2b7d06298178e557ec3320ac  cue-cli-0.11.1.tar.gz
"
