# shellcheck    shell=dash

x log init htag

___X_CMD_HTAG_METADATA="${___X_CMD_ROOT_DATA}/htag/metadata"

xrc:mod:lib     htag        other server  ip  dn

___X_CMD_HTAG_DIR="${___X_CMD_ROOT_DATA}/htag/tag"
___x_cmd_htag___main(){
    [ $# -gt 0 ] || set -- info

    local op="$1";  shift
    case "$op" in
        info|info_|auto|\
        ls|add|rm|has|clear|\
        server|dn|ip)
                "___x_cmd_htag___${op}" "$@" ;;

        --help|-h)
                x help -m htag  ;;
        --*)
                N=host M="unknown option ==> $op" log:ret:64
                ;;
        -*|+*)
                ___x_cmd_htag___handle "$op" "$@" ;;
        *)
                N=host M="unsupported subcmd ==> $op" log:ret:64 ;;
    esac
}

___x_cmd_htag___info(){
    local x_
    if ___x_cmd_htag___server_; then
        printf "server:\t%s\n" "$x_"
    fi

    if ___x_cmd_htag___dn_; then
        printf "dn:\t%s\n" "$x_"
    fi

    if ___x_cmd_htag___ip_; then
        printf "ip:\t%s\n" "$x_"
    fi

    printf "other:\n"
    ___x_cmd_htag___ls | while read -r x_; do
        printf "  - %s\n" "$x_"
    done

}

___x_cmd_htag___auto(){
    ___x_cmd_htag___dn_auto
    ___x_cmd_htag___ip_auto

    ___x_cmd_htag___info
}

___x_cmd_htag___info_(){
    ___x_cmd_htag___info___ 2>/dev/null || true
}

___x_cmd_htag___info___(){
    local x_

    x_htag_server=
    x_htag_dn=
    x_htag_ip=
    x_htag_other=

    if ___x_cmd_htag___server_; then
        x_htag_server="$x_"
    fi

    if ___x_cmd_htag___dn_; then
        x_htag_dn="$x_"
    fi

    if ___x_cmd_htag___ip_; then
        x_htag_ip="$x_"
    fi

    ___x_cmd_htag___load_
    x_htag_other="$x_"

    return 0
}
