# Contributor: solidnerd <niclas@mietz.io>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=glab
pkgver=1.58.0
pkgrel=0
pkgdesc="Open source GitLab CLI tool written in Go"
url="https://gitlab.com/gitlab-org/cli"
arch="all"
license="MIT"
depends="git"
makedepends="go"
options="!check"
subpackages="
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://gitlab.com/gitlab-org/cli/-/archive/v$pkgver/cli-v$pkgver.tar.gz"
builddir="$srcdir/cli-v$pkgver"

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

build() {
	# date seems a little broken to override
	go build -ldflags "
		-X main.debugMode=false
		-X main.version=v$pkgver
		-X main.buildDate=$(date -u "+%Y-%m-%d" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
		-extldflags \"$LDFLAGS\"
		" \
		-o bin/glab \
		./cmd/glab/main.go

	# XXX: When glab is run in fakeroot it segfaults for some reason
	# on ppc64le. By generating the compilation files here we
	# workaround that but we need to investigate why it segfaults in
	# fakeroot eventually.
	bin/glab completion --shell bash > bash.comp
	bin/glab completion --shell zsh > zsh.comp
	bin/glab completion --shell fish > fish.comp
}

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

	install -Dm644 bash.comp "$pkgdir"/usr/share/bash-completion/completions/glab.bash
	install -Dm644 zsh.comp "$pkgdir"/usr/share/zsh/site-functions/_glab
	install -Dm644 fish.comp "$pkgdir"/usr/share/fish/vendor_completions.d/glab.fish
}

sha512sums="
fa8f6ac00a7d2b2bdd3e8197a16e5b1918fea1e62e082e54e44b052d85d83c73bd735c656e81a4e4f09c31e2b2e9db5acc217e1b38629447bdcc86d2ca79faec  glab-1.58.0.tar.gz
"
