# -*- 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/tofuutils/tenv 4.7.21 v
go.offline_build    no
revision            0

homepage            https://tofuutils.github.io/tenv

description         OpenTofu / Terraform / Terragrunt / Atmos version manager
long_description    \
    Versatile version manager for OpenTofu, Terraform, Terragrunt and Atmos. A successor \
    of tofuenv and tfenv.

conflicts           terraform \
                    terragrunt

categories          sysutils
license             Apache-2
maintainers         {icloud.com:github.ssk @suhailskhan} \
                    openmaintainer

checksums           rmd160  84e67829d1fab8c618802163e65fb94194bfef99 \
                    sha256  e320d79495cc15f22386f7b305bb4915fbb5d349e8b6d5713ca1750266cb1275 \
                    size    813965

build.env-append    CGO_ENABLED=0
build.args-append   -o ${worksrcpath}/build/ \
                    -ldflags="-s -w -X main.version=${version}" \
                    ${worksrcpath}/cmd/*

post-build {
    foreach shell {zsh bash fish} {
        system -W ${worksrcpath} "./build/${name} completion ${shell} > tenv.${shell}"
    }
}

destroot {
    foreach bin [glob ${worksrcpath}/build/*] {
        xinstall -m 755 ${bin} ${destroot}${prefix}/bin
    }

    xinstall -d ${destroot}${prefix}/share/zsh/site-functions
    xinstall -m 644 ${worksrcpath}/${name}.zsh \
        ${destroot}${prefix}/share/zsh/site-functions/_${name}

    xinstall -d ${destroot}${prefix}/share/bash-completion/completions
    xinstall -m 644 ${worksrcpath}/${name}.bash \
        ${destroot}${prefix}/share/bash-completion/completions/${name}

    xinstall -d ${destroot}${prefix}/share/fish/vendor_completions.d
    xinstall -m 644 ${worksrcpath}/${name}.fish \
        ${destroot}${prefix}/share/fish/vendor_completions.d

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} \
        README.md CHANGELOG.md LICENSE SECURITY.md TENV_AS_LIB.md \
        ${destroot}${prefix}/share/doc/${name}
}

test.run            yes
test.cmd            ${prefix}/bin/tenv help
