# shellcheck shell=sh disable=SC3043

# https://www.jianshu.com/p/bd37bb185e8b

mirror_maven(){
    local op
    if [ $# -eq 0 ]; then
        op=help
    else
        case "$op" in
            -h|--help)      op=help ;;
            -v|--version)   op=version ;;
        esac
        op="$1"; shift
    fi

    case "$op" in
        help)                       ;;
        version)                    ;;
        url)                        mirror_maven_url "$@" ;;
    esac
}

mirror_maven_url(){
    local op
    if [ -n "$1" ]; then
        op=$1
    else
        op=ali
    fi

    case "$op" in
        repo1)
            ___x_cmd_cmds_cat <<A
<mirror>
    <id>repo1</id>
    <mirrorOf>central</mirrorOf>
    <name>official maven repo1</name>
    <url>http://repo2.maven.org/maven2/</url>s
</mirror>
A
        ;;
        repo2)
            ___x_cmd_cmds_cat <<A
<mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>official maven repo2</name>
    <url>http://repo2.maven.org/maven2/</url>
</mirror>
A
            ;;
        uk|uk-maven|uk.maven.org)
            ___x_cmd_cmds_cat <<A
<mirror>
    <id>ui</id>
    <mirrorOf>central</mirrorOf>
    <name>uk-maven</name>
    <url>http://uk.maven.org/maven2/</url>
</mirror>
A
            ;;
        jboss)
            ___x_cmd_cmds_cat <<A
<mirror>
    <id>jboss-public-repository-group</id>
    <mirrorOf>central</mirrorOf>
    <name>JBoss Public Repository Group</name>
    <url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
A
        ;;
        ali)
            ___x_cmd_cmds_cat <<A
<mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>*</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
A
            ;;
        net-cn|net.cn)
            ___x_cmd_cmds_cat <<A
<mirror>
    <id>net-cn</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://maven.net.cn/content/groups/public/</url>
</mirror>
A
            ;;
        ibiblio)
            ___x_cmd_cmds_cat <<A
<mirror>
    <id>ibiblio</id>
    <mirrorOf>central</mirrorOf>
    <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
    <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
A
        ;;

        # TODO: add self-defined new mirror
        http://|https://)           printf "$op" ;;
        *)                          echo "Unrecognized source name"; return 1
    esac
}
