# -*- 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.6.2 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  4d3775f003b8b6e4c027f149c9a30a509b83ce46 \
                     sha256  f3ebd348301163509d23c0cb6963c6f69bc9b942c54188c09605cd63f08475a0 \
                     size    810827

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
