# -*- 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.14.8 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  67654f5760b333a3adce0a5f7990ea92e3c182f2 \
                    sha256  41094ae845744e9db572875415f8fbcffa8d335491f96567fa998dca36487f9d \
                    size    821315

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
