# -*- 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/superfly/flyctl 0.4.67 v
go.offline_build    no
revision            0

categories          devel
installs_libs       no
license             Apache-2
maintainers         {netinertia.co.uk:jamesog @jamesog} \
                    {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

description         Command line tools for fly.io services
long_description    ${name} is a command-line interface for fly.io.

homepage            https://fly.io

checksums           rmd160  55b4d91339d5ab5fdb26e28aa4a4da3d6617b210 \
                    sha256  74dfecfdf368a23e09c14492c03934dbb7eefba57c9cc60926783169e57eda6b \
                    size    1961097

build.cmd           "${go.bin} generate ./... && ${go.bin} build"

# Hard-code the build date to help with build reproducibility
build.pre_args-append \
    -o ./_bin/${name} \
    -ldflags \" \
        -X ${go.package}/internal/buildinfo.environment=production \
        -X ${go.package}/internal/buildinfo.branchName=v${version} \
        -X ${go.package}/internal/buildinfo.buildDate=2024-02-15T00:00:00Z \
        -X ${go.package}/internal/buildinfo.buildVersion=v${version} \
        -X ${go.package}/internal/buildinfo.commit=release \
    \"

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

    ln -s ${prefix}/bin/${name} ${destroot}${prefix}/bin/fly

    # Shell completion
    xinstall -d "${destroot}${prefix}/etc/bash_completion.d"
    xinstall -d "${destroot}${prefix}/share/zsh/site-functions"
    xinstall -d "${destroot}${prefix}/share/fish/vendor_completions.d"
    system "${destroot}${prefix}/bin/${name} completion bash > \\
        ${destroot}${prefix}/etc/bash_completion.d/${name}"
    system "${destroot}${prefix}/bin/${name} completion zsh >  \\
        ${destroot}${prefix}/share/zsh/site-functions/_${name}"
    system "${destroot}${prefix}/bin/${name} completion fish > \\
        ${destroot}${prefix}/share/fish/vendor_completions.d/${name}.fish"
}

# Only match releases. Pre-releaes have a "-pre-N" suffix
github.livecheck.regex {(\d+(?:\.\d+)+)}
