# -*- 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/docker/cli 29.6.1 v
revision            0
name                docker
categories          devel
license             Apache-2
maintainers         {emcrisostomo @emcrisostomo} \
                    openmaintainer
description         Utilities for the open-source application container engine
long_description    Docker is an open source project to pack, ship \
                    and run any application as a lightweight container. \
                    This port contains command line utilities for interacting \
                    with Docker, but not the core daemon.

checksums           rmd160  b15d5b83592f1c51f6f9a82e02346475a4dbeb6e \
                    sha256  74d14dd212b07cd3328989dc6a029dde2ebbe6a878199eaaafad54916f456194 \
                    size    6869604

build.target        github.com/docker/cli/cmd/docker

depends_build-append \
                    bin:go-md2man:go-md2man

post-patch {
    reinplace s+/usr/lib+${prefix}/lib+g \
        ${worksrcpath}/cli-plugins/manager/manager_unix.go
}

pre-build {
    build.cmd ${go.bin} build -ldflags \
        "\"-X github.com/docker/cli/cli/version.Version=${version}\""
}

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

    foreach src [glob ${worksrcpath}/man/*.?.md] {
        set page [file rootname [file tail ${src}]]
        set section [string range [file extension ${page}] 1 end]
        set dst ${destroot}${prefix}/share/man/man${section}/${page}

        # skip dockerd; it's not provided on macOS
        if {${page} ne "dockerd.8"} {
        ui_info "${src} -> ${dst}"
        xinstall -d [file dirname ${dst}]
            system -W ${worksrcpath}/man "go-md2man -out ${dst} -in ${src}"
        }
    }

    # install completion for various shells
    set bash_completions_dir ${destroot}${prefix}/share/bash-completion/completions
    set fish_completions_dir ${destroot}${prefix}/share/fish/vendor_completions.d
    set zsh_completions_dir ${destroot}${prefix}/share/zsh/site-functions
    xinstall -d \
        ${bash_completions_dir} \
        ${fish_completions_dir} \
        ${zsh_completions_dir}
    xinstall -m 644 \
        [glob ${worksrcpath}/contrib/completion/bash/*] \
        ${bash_completions_dir}
    xinstall -m 644 \
        [glob ${worksrcpath}/contrib/completion/fish/*] \
        ${fish_completions_dir}
    xinstall -m 644 \
        [glob ${worksrcpath}/contrib/completion/zsh/*] \
        ${zsh_completions_dir}
}

github.livecheck.regex  {([^"r]+)}

notes "\
    This port only contains a utility for working with Docker; to run\
    containers locally, install e.g. the colima port."
