# shellcheck shell=dash

xrc:mod:lib     ifconfig   show

___x_cmd_ifconfig___main(){
    [ "$#" -gt 0 ] ||   set -- show

    local op="$1";      shift
    case "$op" in
        -h|--help)      ___x_cmd help -m ifconfig       "$@" ;      return 0 ;;
        show)           ___x_cmd_ifconfig_show          "$@" ;;
        check)          ___x_cmd_ifconfig_check         "$@" ;;

        colr)           ___x_cmd_ifconfig_colr          "$@" ;;
        tsv)            ___x_cmd_ifconfig_tsv           "$@" ;;

        *)              ___x_cmd_ifconfig_show "$op"    "$@" ;;
    esac
}

___x_cmd_ifconfig___check(){
    ! ___x_cmd_hascmd ifconfig  || return 0
    ! ___x_cmd os is linux      || return 0     # Using busybox
    ! ___x_cmd os is win        || return 0

    # ! ___x_cmd os is win        || N=ifconfig M="ifconfig is not avaiable in windows. Try 'ipconfig' or 'x ip config'" log:ret:1
    ! ___x_cmd_hascmd ip        || N=ifconfig M="ifconfig is not avaiable. Try 'x ip addr'" log:ret:1
    return 1
}

___x_cmd_ifconfig_check(){
    if ___x_cmd_ifconfig___check; then
        ifconfig:info "ifconfig is avaiable."
    else
        ifconfig:info "ifconfig is not avaiable."
    fi
}

___x_cmd_ifconfig_tsv(){
    case "$1" in
        busybox)            ___x_cmd_cmds awk -f "$___X_CMD_ROOT_MOD/ifconfig/lib/awk/ifconfig.busybox.awk" ;;
        darwin)             ___x_cmd_cmds awk -f "$___X_CMD_ROOT_MOD/ifconfig/lib/awk/ifconfig.darwin.awk"  ;;
        gnu)                ___x_cmd_cmds awk -f "$___X_CMD_ROOT_MOD/ifconfig/lib/awk/ifconfig.gnu.awk"     ;;
    esac
}

___x_cmd_ifconfig_colr(){
    ___x_cmd_cmds awk -f "$___X_CMD_ROOT_MOD/ifconfig/lib/awk/ifconfig.colr.awk"
}
