# shellcheck shell=dash disable=2016

___x_cmd_uptime___main(){
    [ "$#" -gt 0 ] || set -  --yml

    local op="$1"; shift
    case "$op" in
        --help|-h)      ___x_cmd help -m uptime "$@" ;;
        --yml)          ___x_cmd_uptime___cmd_yml ;;
        --raw)          ___x_cmd_uptime___cmd_raw "$@" ;;
        *)              ___x_cmd_uptime___cmd_raw "$op" "$@" ;;
    esac
}

___x_cmd_uptime___cmd_raw(){
    if ___x_cmd hascmd uptime; then
        ___x_cmd_uptime___cmd_raw(){
            ___x_cmd_cmds uptime "$@"
        }
    elif ___x_cmd hascmd busybox && ___x_cmd_cmds busybox uptime 2>/dev/null 1>&2; then
        ___x_cmd_uptime___cmd_raw(){
            ___x_cmd_cmds busybox uptime
        }
    else
        ___x_cmd_uptime___cmd_raw(){
            ___x_cmd cosmo uptime "$@"
        }
    fi

    ___x_cmd_uptime___cmd_raw "$@"
}

___x_cmd_uptime___cmd_yml(){
    local NO_COLOR="$NO_COLOR"
    ___x_cmd_is_stdout2tty || NO_COLOR=1
    ___x_cmd_uptime___cmd_raw 2>/dev/null | \
        ___x_cmd_cmds awk -v NO_COLOR="$NO_COLOR" -f "$___X_CMD_ROOT_MOD/uptime/lib/parse.awk"
}
