-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
output.sh
84 lines (77 loc) · 1.55 KB
/
output.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
# This is technically redundant, since all consumers of this lib will have enabled these,
# however, it helps Shellcheck realise the options under which these functions will run.
set -euo pipefail
ANSI_BLUE='\033[1;34m'
ANSI_RED='\033[1;31m'
ANSI_YELLOW='\033[1;33m'
ANSI_RESET='\033[0m'
# Output a single line step message to stdout.
#
# Usage:
# ```
# output::step "Installing Python ..."
# ```
function output::step() {
echo "-----> ${1}"
}
# Indent passed stdout. Typically used to indent command output within a step.
#
# Usage:
# ```
# pip install ... | output::indent
# ```
function output::indent() {
sed --unbuffered "s/^/ /"
}
# Output a styled multi-line notice message to stderr.
#
# Usage:
# ```
# output::notice <<-EOF
# Note: The note summary.
#
# Detailed description.
# EOF
# ```
function output::notice() {
echo >&2
while IFS= read -r line; do
echo -e "${ANSI_BLUE} ! ${line}${ANSI_RESET}" >&2
done
echo >&2
}
# Output a styled multi-line warning message to stderr.
#
# Usage:
# ```
# output::warning <<-EOF
# Warning: The warning summary.
#
# Detailed description.
# EOF
# ```
function output::warning() {
echo >&2
while IFS= read -r line; do
echo -e "${ANSI_YELLOW} ! ${line}${ANSI_RESET}" >&2
done
echo >&2
}
# Output a styled multi-line error message to stderr.
#
# Usage:
# ```
# output::error <<-EOF
# Error: The error summary.
#
# Detailed description.
# EOF
# ```
function output::error() {
echo >&2
while IFS= read -r line; do
echo -e "${ANSI_RED} ! ${line}${ANSI_RESET}" >&2
done
echo >&2
}