tdl/hack/lib.sh
2024-11-17 19:11:41 +08:00

45 lines
813 B
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT_MODULE=$(go list -m)
function set_root_dir {
# shellcheck disable=SC2034
ROOT_DIR=$(go list -f '{{.Dir}}' "${ROOT_MODULE}")
}
set_root_dir
#### Convenient IO methods #####
COLOR_RED='\033[0;31m'
COLOR_ORANGE='\033[0;33m'
COLOR_GREEN='\033[0;32m'
COLOR_BLUE='\033[0;94m'
COLOR_BOLD='\033[1m'
COLOR_NONE='\033[0m' # No Color
function log_error {
>&2 echo -n -e "${COLOR_BOLD}${COLOR_RED}"
>&2 echo "$@"
>&2 echo -n -e "${COLOR_NONE}"
}
function log_warn {
>&2 echo -n -e "${COLOR_ORANGE}"
>&2 echo "$@"
>&2 echo -n -e "${COLOR_NONE}"
}
function log_succ {
>&2 echo -n -e "${COLOR_GREEN}"
>&2 echo "$@"
>&2 echo -n -e "${COLOR_NONE}"
}
function log_info {
>&2 echo -n -e "${COLOR_BLUE}"
>&2 echo "$@"
>&2 echo -n -e "${COLOR_NONE}"
}