Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/all_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ run_step() {
log_info "[$STEP_NO] $title"

if "$@" >"$log_path" 2>&1; then
log_success "$title completed"
log_info "$title completed"
return 0
fi

Expand All @@ -47,9 +47,9 @@ STEP_NO="1/3"
log_info "[$STEP_NO] Clean build artifacts"
if [[ -d "$BIN_DIR" ]]; then
rm -rf "$BIN_DIR"
log_success "Removed $BIN_DIR"
log_info "Removed $BIN_DIR"
else
log_success "No existing build artifacts"
log_info "No existing build artifacts"
fi

STEP_NO="2/3"
Expand All @@ -58,5 +58,5 @@ run_step "Run tests" "test" make test
STEP_NO="3/3"
run_step "Build CLI" "build" make build

log_success "Binary ready at $BIN_PATH"
log_info "Binary ready at $BIN_PATH"
print_run_summary "Build completed"
29 changes: 24 additions & 5 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,32 @@ set -euo pipefail
_log() {
local level="$1"
local color="$2"
shift 2
printf '\033[%sm[%s]\033[0m %s %s\n' "$color" "$level" "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
local stream="${3:-stdout}"
shift 3

local line
line="$(date '+%Y-%m-%d %H:%M:%S') [${level}] $*"

if [[ "$stream" == "stderr" ]]; then
if [[ -t 2 ]]; then
printf '\033[%sm%s\033[0m\n' "$color" "$line" >&2
else
printf '%s\n' "$line" >&2
fi
return
fi

if [[ -t 1 ]]; then
printf '\033[%sm%s\033[0m\n' "$color" "$line"
return
fi

printf '%s\n' "$line"
}

log_info() { _log "INFO" "34" "$@"; }
log_success() { _log "SUCCESS" "32" "$@"; }
log_error() { _log "ERROR" "31" "$@" >&2; }
log_info() { _log "INFO" "32" "stdout" "$@"; }
log_success() { log_info "$@"; }
log_error() { _log "ERROR" "31" "stderr" "$@"; }

default_shell_rc() {
case "$(basename "${SHELL:-}")" in
Expand Down
29 changes: 21 additions & 8 deletions scripts/lib/log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,42 @@ SCRIPT_START_TS="$(date +%s)"
_log() {
local level="$1"
local color="$2"
shift 2
local stream="${3:-stdout}"
shift 3

local now
now="$(date '+%Y-%m-%d %H:%M:%S')"
local line
line="${now} [${level}] $*"

if [[ "$stream" == "stderr" ]]; then
if [[ -t 2 ]]; then
printf '\033[%sm%s\033[0m\n' "$color" "$line" >&2
else
printf '%s\n' "$line" >&2
fi
return
fi

if [[ -t 1 ]]; then
printf '\033[%sm[%s]\033[0m %s %s\n' "$color" "$level" "$now" "$*"
else
printf '[%s] %s %s\n' "$level" "$now" "$*"
printf '\033[%sm%s\033[0m\n' "$color" "$line"
return
fi

printf '%s\n' "$line"
}

log_info() { _log "INFO" "34" "$@"; }
log_success() { _log "SUCCESS" "32" "$@"; }
log_error() { _log "ERROR" "31" "$@" >&2; }
log_info() { _log "INFO" "32" "stdout" "$@"; }
log_success() { log_info "$@"; }
log_error() { _log "ERROR" "31" "stderr" "$@"; }

print_run_summary() {
local message="$1"
local elapsed end_at
elapsed="$(( $(date +%s) - SCRIPT_START_TS ))"
end_at="$(date '+%Y-%m-%d %H:%M:%S %Z')"

log_success "$message"
log_info "$message"
log_info "Elapsed: ${elapsed}s"
log_info "Completed at: ${end_at}"
}
29 changes: 24 additions & 5 deletions scripts/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,32 @@ set -euo pipefail
_log() {
local level="$1"
local color="$2"
shift 2
printf '\033[%sm[%s]\033[0m %s %s\n' "$color" "$level" "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
local stream="${3:-stdout}"
shift 3

local line
line="$(date '+%Y-%m-%d %H:%M:%S') [${level}] $*"

if [[ "$stream" == "stderr" ]]; then
if [[ -t 2 ]]; then
printf '\033[%sm%s\033[0m\n' "$color" "$line" >&2
else
printf '%s\n' "$line" >&2
fi
return
fi

if [[ -t 1 ]]; then
printf '\033[%sm%s\033[0m\n' "$color" "$line"
return
fi

printf '%s\n' "$line"
}

log_info() { _log "INFO" "34" "$@"; }
log_success() { _log "SUCCESS" "32" "$@"; }
log_error() { _log "ERROR" "31" "$@" >&2; }
log_info() { _log "INFO" "32" "stdout" "$@"; }
log_success() { log_info "$@"; }
log_error() { _log "ERROR" "31" "stderr" "$@"; }

default_shell_rc() {
case "$(basename "${SHELL:-}")" in
Expand Down
Loading