maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=cue-cli
pkgver=0.12.1
pkgrel=0
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="
1e52e856d773bf38bc7e0da000adbcea3d3cde0bed3d01643497a859597499d5d3512f5627f51cbaf5ac3bc15fd19c3f22878e0545999074c12e1ea18195825b  cue-cli-0.12.1.tar.gz
"
