# shellcheck shell=dash

___x_cmd log init tping

xrc:mod:lib tping       run

___x_cmd_tping___main(){
    [ "$#" -gt 0 ]  ||   set -- --help

    local op="$1";  shift
    case "$op" in
        -h|--help)  ___x_cmd help -m tping "$@" ;;

        run|--)     ___x_cmd_tping_run          "$@" ;;

        test)       ___x_cmd_tping_test         "$@" ;;
        *)          ___x_cmd_tping_run "$op"    "$@" ;;
    esac
}

___x_cmd_tping_test(){
    ___x_cmd_tping_run___raw_cmd_run "$1" "${2:-80}" 2>/dev/null | {
        local line
        read -r line

        case "$line" in
            0\ *)       tping:debug "Fail because of data -> |$line|"
                        return 1 ;;
            *)          tping:debug "Succ because of data -> |$line|"
                        return 0 ;;
        esac
    }
}

