

___x_cmd_ip_addr(){

    ___x_cmd_ip_addr___check || return $?

    local format=auto
    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)      ___x_cmd help -m ip addr "$@" ;;
            --app)          format=app  ;;
            --tsv)          format=tsv  ;;
            --csv)          format=csv  ;;
            --raw)          format=raw  ;;
            -r|--colr)      format=colr ;;
            --auto)         format=auto ;;
            *)              break ;;
        esac
        shift
    done

    ___x_cmd_ip_addr___"$format" "$@"
}

___x_cmd_ip_addr___check(){
    ! ___x_cmd_hascmd ip    || return 0
    ___x_cmd os is linux    || {
        ip:error "Command not found -> ip"
        ip:warn "ip command is not avaiable on non-linux platform. Try using 'x ip config' or 'x ifconfig' as alternatives."
        return 1
    }
}

___x_cmd_ip_addr___auto(){
    if ___x_cmd_is_stdout2tty; then     ___x_cmd_ip_addr___app    "$@"
    else                                ___x_cmd_ip_addr___tsv    "$@"
    fi
}

___x_cmd_ip_addr___colrpipe(){
    ___x_cmd_cmds awk -f "$___X_CMD_ROOT_MOD/ip/lib/addr/awk/ipaddr.colr.awk"
}

___x_cmd_ip_addr___colr(){
    ___x_cmd_ip_addr___raw | ___x_cmd_ip_addr___colrpipe
}

___x_cmd_ip_addr___raw(){
    if ___x_cmd_hascmd ip; then
        ___x_cmd_cmds ip addr
    elif ___x_cmd_is_termux; then
        # requires root.
        # ___x_cmd_cmds pkg install iproute2
        # ___x_cmd_cmds ip addr
        N=ip M="In termux please use 'x ip c' instead" log:ret:1
    else
        ___x_cmd busybox ip addr
    fi
}

___x_cmd_ip_addr___tsv(){
    ___x_cmd_ip_addr___raw | \
        ___x_cmd_cmds awk -f \
            "$___X_CMD_ROOT_MOD/ip/lib/addr/awk/ip.gnu.awk"
}

___x_cmd_ip_addr___csv(){
    ___x_cmd_ip_addr___tsv | ___x_cmd tsv tocsv
}

___x_cmd_ip_addr___app(){
    ___x_cmd_ip_addr___csv | ___x_cmd csv app
}
