# -*- 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            github.com/jenkins-zh/jenkins-cli 0.0.46 v
# Delete this on next update to use golang PortGroup's default ('archive')
github.tarball_from tarball
set git_commit      bd33a1b
categories          devel
license             MIT

maintainers         {@harens harens} openmaintainer
description         Allows you manage your Jenkins as an easy way
long_description    Jenkins CLI allows you manage your Jenkins in an easy way. \
                    No matter if you're a plugin developer, administrator or just a \
                    regular user, it is made for you!

# Name of the executable
set short           jcli

homepage            https://${short}.jenkins-zh.cn

checksums           ${distname}${extract.suffix} \
                        rmd160  6ecfe78efa3c764cb2ae29dfb758f4f2a46c3a86 \
                        sha256  084e721ef9edd6880dfbdbad9f0224f29a06dd42252c9768e0847c94061deab0 \
                        size    224132

# Allows for version number, last commit and build date in `jcli version`
# Suppress build date for reproducible builds
set build_date      SUPPRESSED
set cobra_extension github.com/linuxsuren/cobra-extension/version

# Issues with vendored deps: allow fetching deps at build time
go.offline_build no

build.args          -ldflags \
                      '-X ${cobra_extension}.date=${build_date} \
                       -X ${cobra_extension}.commit=${git_commit} \
                       -X ${cobra_extension}.version=${version}'

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

post-destroot {

    copy ${worksrcpath}/docs/book \
        ${destroot}${prefix}/share/doc/${name}

    # Docs files that aren't in the books dir
    foreach f {CONTRIBUTING.md LICENSE README-zh.md} {
            copy ${worksrcpath}/${f} ${destroot}${prefix}/share/doc/${name}
    }

    # bash completion
    set bash_completion_dir ${destroot}${prefix}/share/bash-completion/completions
    xinstall -d ${bash_completion_dir}
    system -W ${worksrcpath} "${worksrcpath}/${name} completion --type bash > ${bash_completion_dir}/${short}"

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

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