
___x_cmd_nets_update(){
    local datadir="${___X_CMD_NETS_DATA}/latest"

    if [ -f "$datadir/all" ] && ___x_cmd fileage --in 300s "$datadir/all"; then
        ___x_cmd ui yesno "The file is updated in less than 5 min. Do you want to update ?"
        case $? in
            0)      ;;
            130)    return 130 ;;
            *)      return 0
        esac
    fi

    ___x_cmd rmrf "$datadir"
    ___x_cmd mkdirp "$datadir"
    ___x_cmd_nets_update___raw
    ___x_cmd ps --tsv >"$datadir/ps.tsv"
    nets:info --data "$datadir" "Update suscces"

    ___x_cmd_nets_convert "$datadir" || return $?

    nets:info "Preprocessing suscces."

    nets:info --next 'x nets ls' "Using 'x nets ls' to show the tables availables"
    nets:info --next 'x nets view' "Using 'x nets view [table name, optional]' to intereact with the table"
}

# collect then parse
___x_cmd_nets_update___raw(){
    if ___x_cmd os is linux; then
        if ___x_cmd_hascmd netstat; then
            ___x_cmd_cmds netstat -anp | ___x_cmd_nets_update___raw___all
        else
            ___x_cmd busybox netstat | ___x_cmd_nets_update___raw___all
        fi
    elif ___x_cmd os is win; then
        LC_ALL="$___X_CMD_LOCALE_DEF_C" "${___X_CMD_ROOT_MOD}/nets/lib/netstat.bat" -no | ___x_cmd_nets_update___raw___all
    elif ___x_cmd os is darwin; then
        ___x_cmd_cmds netstat -anv | ___x_cmd_nets_update___raw___all
    else
        if ___x_cmd_hascmd netstat; then
            ___x_cmd_cmds netstat -an | ___x_cmd_nets_update___raw___all
        else
            nets:error "No netstat found."
            return 1
        fi
    fi
}

___x_cmd_nets_update___raw___all(){
    # tee "$datadir/all" | ___x_cmd log uirotate

    ___x_cmd_cmds awk -v datafp="$datadir/all" '{ print >>datafp ; print; fflush("/dev/stdout"); }' | ___x_cmd log uirotate --clear
}

