# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           golang 1.0

go.setup            gitlab.com/gitlab-org/cli 1.107.0 v
name                glab
revision            0
categories          devel
license             MIT

maintainers         {@harens harens} openmaintainer
description         A GitLab CLI tool bringing GitLab to your command line
long_description    ${name} is an open source GitLab CLI tool \
                    bringing GitLab to your terminal next to where \
                    you are already working with git and your code.

checksums           ${distname}${extract.suffix} \
                    rmd160  fea975b549e2d16effad3673ad16b9b1aeae2009 \
                    sha256  10b7acef12221dda93901b125c4502cfb5594820216faf40880b8f079acd48d8 \
                    size    17712714

# If not set, it states that it's a developer build
# Suppress build date for reproducible builds
# Switch to SOURCE_DATE_EPOCH approach in the future
# See https://trac.macports.org/ticket/59672
set build_date      SUPPRESSED

build.pre_args      -ldflags \
                      '-X main.build=${build_date} \
                       -X main.version=${version}'

build.args          ${worksrcpath}/cmd/glab

destroot {
    xinstall -m 755 ${worksrcpath}/${name} ${destroot}${prefix}/bin/
}

post-destroot {
    # install documentation
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} LICENSE README.md ${destroot}${prefix}/share/doc/${name}

    # bash completion
    set bash_completion_dir ${destroot}${prefix}/etc/bash_completion.d
    xinstall -d ${bash_completion_dir}
    system -W ${worksrcpath} "${worksrcpath}/${name} completion --shell bash > ${bash_completion_dir}/${name}"

    # zsh completion
    set zsh_completion_dir ${destroot}${prefix}/share/zsh/site-functions
    xinstall -d ${zsh_completion_dir}
    system -W ${worksrcpath} "${worksrcpath}/${name} completion --shell zsh > ${zsh_completion_dir}/_${name}"

    # fish completion
    set fish_completion_dir ${destroot}${prefix}/share/fish/vendor_completions.d
    xinstall -d ${fish_completion_dir}
    system -W ${worksrcpath} "${worksrcpath}/${name} completion --shell fish > ${fish_completion_dir}/${name}.fish"
}

# Allow Go to fetch dependencies at build time
go.offline_build no

# See below if/when going back to listing dependencies

# The GitLab PG uses bzip2 for the distfile, but this messes with the Go deps which are tar files.
#extract.suffix .tar.gz
#use_bzip2 no

# Notes for updating
# go.googlesource.com/protobuf --> github.com/protocolbuffers/protobuf-go
# github.com/AlecAivazis/survey --> github.com/go-survey/survey
# github.com/MakeNowJust/heredoc --> github.com/makenowjust/heredoc
# github.com/AlecAivazis/survey needs to be at least v2.3.6
# (See https://github.com/go-survey/survey/issues/415)
# This seems to lead to cursor errors?
# Delete yaml.v2
