# -*- 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           github 1.0

github.setup        mas-cli mas 2.3.0 v
github.tarball_from archive
set git-commit      c93a4fc
# This line is for displaying commit in CLI only
revision            0
categories          sysutils
description         Mac App Store command line interface
long_description    A simple command line interface for the Mac App Store. \
                    Designed for scripting and automation.
license             MIT

maintainers         {kimuraw @kimuraw} \
                    {judaew @judaew} \
                    openmaintainer

checksums           sha256  fbbd172d9c6adeff06e1166d68b287dc1ee56a1440c6c360b61f9f777041ae7a \
                    rmd160  2e223f1d98a5b4f9524f9fb0ffa493ffb4bf60cf \
                    size    159895

use_configure       no
use_xcode           yes

# requirements:
# - mas: Xcode 11.4 or later
set xcodeversion_min_required 11.4
pre-fetch {
    if {[vercmp ${xcodeversion} ${xcodeversion_min_required}] < 0} {
        ui_error "${name} @${version} requires Xcode ${xcodeversion_min_required} or later but you have Xcode ${xcodeversion}."
        ui_error "See https://guide.macports.org/chunked/installing.xcode.html for download links."
        return -code error "incompatible Xcode version"
    }
}

post-patch {
    reinplace "s|\$(Scripts/version)|${version}|" ${worksrcpath}/Scripts/generate_package_swift
    reinplace "s|\${1:-unknown}|MacPorts|" ${worksrcpath}/Scripts/generate_package_swift
    reinplace "s|\$(git remote get-url origin)|${git.url}|" ${worksrcpath}/Scripts/generate_package_swift
    reinplace "s|\$(git rev-parse HEAD)|${git-commit}|" ${worksrcpath}/Scripts/generate_package_swift
}

pre-configure {
    system -W ${worksrcpath} "./Scripts/generate_package_swift"
}

build.cmd           swift
build.target        build
build.args          --configuration release \
                    --arch ${configure.build_arch} \
                    --disable-sandbox

destroot {
    xinstall -m 0755 ${worksrcpath}/.build/${configure.build_arch}-apple-macosx/release/${name} \
        ${destroot}${prefix}/bin/${name}

    set bash_complete ${prefix}/share/bash-completion/completions
    xinstall -d ${destroot}${bash_complete}
    xinstall -m 0644 ${worksrcpath}/contrib/completion/mas-completion.bash \
        ${destroot}${bash_complete}/${name}

    set fish_complete ${prefix}/share/fish/vendor_completions.d
    xinstall -d ${destroot}${fish_complete}
    xinstall -m 0644 ${worksrcpath}/contrib/completion/mas.fish \
        ${destroot}${bash_complete}/${name}.fish
}

github.livecheck.regex  {([0-9.]+)}
