# -*- 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 28.3.3 v
# Delete this on next update to use golang PortGroup's default ('archive')
github.tarball_from tarball
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  22b18668f8e245344f64c6d7c0a5bec32539528b \
                    sha256  b2782833c4be762ecb60f6c1af3e88eaf760e4cd54a4cc36d5a66df6fb3e1dfc \
                    size    7611098

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 {
    set distfile_dirname [exec tar tzf ${distpath}/[lindex ${distfiles} 0] | sed -n 1p]
    set docker_gitcommit [string map "${github.author}-${github.project}- {} / {}" ${distfile_dirname}]
    if {![regexp -nocase -- {^[0-9a-f]{7}$} ${docker_gitcommit}]} {
        return -code error "can't determine git commit"
    }

    set val [clock microseconds]
    set seconds_precision [expr { $val / 1000000 }]
    set build_time [clock format $seconds_precision -format "%a %b %d %H:%M:%S %Y"]

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

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."
