# Maintainer: @naveen521kk on Github <naveen521kk@gmail.com>

_realname=github-cli
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.12.1
pkgrel=1
pkgdesc='The GitHub CLI (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/cli/cli"
license=('MIT')
depends=("winpty")
makedepends=("${MINGW_PACKAGE_PREFIX}-go")
checkdepends=("git")
optdepends=("git: To interact with repositories")
options=('!strip')
source=("$_realname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz"
        "gh")
sha256sums=('14ef58fb2f09da1d66194527e1e8b637d28d972d273a6a627056aa960a9a9121'
            '9ee5f2b44b7e9aa751508f02c1020e341e0212a9aa146b7428eb5ffea310be27')
build() {
    cd "cli-$pkgver"
    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GO_LDFLAGS="-s -w"
    export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"

    make GH_VERSION="v$pkgver" bin/gh.exe manpages
    bin/gh.exe completion -s bash | install -Dm644 /dev/stdin bash-completion/completions/gh
    bin/gh.exe completion -s zsh | install -Dm644 /dev/stdin zsh/site-functions/_gh
    bin/gh.exe completion -s fish | install -Dm644 /dev/stdin fish/vendor_completions.d/gh.fish
}

check(){
    cd "cli-$pkgver"
    make test
}

package() {
    cd "cli-$pkgver"
    install -Dm755 "${srcdir}/gh" "${pkgdir}${MINGW_PREFIX}/bin/gh"
    install -Dm755 "bin/gh.exe" "${pkgdir}${MINGW_PREFIX}/bin/gh.exe"
    cp -r share/ "${pkgdir}${MINGW_PREFIX}/"
    install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
    install -Dm644 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
    install -Dm644 bash-completion/completions/gh "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/gh"
    install -Dm644 zsh/site-functions/_gh "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_gh"
    install -Dm644 fish/vendor_completions.d/gh.fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/gh.fish"
}
