Skip to content

Commit 54678fb

Browse files
author
Jarmo Pertman
committed
Add command line option for removing colored output
1 parent 61429d7 commit 54678fb

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

candalf.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Usage: $(basename "$0") [-v | --verbose] [-d | --dry-run] SERVER SPELL_BOOK...
77
Options:
88
-d --dry-run do not cast any spells, but show what would be casted
99
-v --verbose enable verbose output
10+
-n --no-color disable colored output
1011
-h --help show this help
1112
1213
Examples:
@@ -22,7 +23,9 @@ if [[ ${#} -eq 0 ]]; then
2223
usage
2324
fi
2425

25-
optspec=":dvh-:"
26+
COLOR_RESET="\\033[0;0m"
27+
28+
optspec=":dvnh-:"
2629
while getopts "$optspec" optchar; do
2730
case "${optchar}" in
2831
-)
@@ -33,6 +36,9 @@ while getopts "$optspec" optchar; do
3336
verbose)
3437
VERBOSE=1
3538
;;
39+
no-color)
40+
NO_COLOR=$COLOR_RESET
41+
;;
3642
help)
3743
usage
3844
;;
@@ -48,6 +54,9 @@ while getopts "$optspec" optchar; do
4854
v)
4955
VERBOSE=1
5056
;;
57+
n)
58+
NO_COLOR=$COLOR_RESET
59+
;;
5160
h)
5261
usage
5362
;;
@@ -64,6 +73,7 @@ VERBOSE="${VERBOSE:-""}"
6473
test $VERBOSE && set -x
6574
set -Eeuo pipefail
6675

76+
export CANDALF_NO_COLOR="${NO_COLOR:-""}"
6777
export CANDALF_DRY_RUN="${DRY_RUN:-""}"
6878
CANDALF_ROOT=$(dirname "$(realpath "$0")")
6979
CANDALF_SERVER=${1:?"SERVER not set!"}

lib/cast.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ set -Eeuo pipefail
88
. "$CANDALF_ROOT"/lib/candalf-env.sh
99
eval "$(candalfEnv)"
1010

11-
COLOR_RED='\033[0;31m'
12-
COLOR_GREEN='\033[0;32m'
13-
COLOR_GREEN_BG='\033[0;42m'
14-
COLOR_YELLOW='\033[0;33m'
15-
COLOR_YELLOW_BG='\033[0;43m'
16-
COLOR_MAGENTA='\033[0;35m'
17-
COLOR_GREY='\033[0;90m'
18-
COLOR_END='\033[0m'
11+
CANDALF_NO_COLOR="${CANDALF_NO_COLOR:-""}"
12+
COLOR_RED="${CANDALF_NO_COLOR:-"\\033[0;31m"}"
13+
COLOR_GREEN="${CANDALF_NO_COLOR:-"\\033[0;32m"}"
14+
COLOR_GREEN_BG="${CANDALF_NO_COLOR:-"\\033[0;42m"}"
15+
COLOR_YELLOW="${CANDALF_NO_COLOR:-"\\033[0;33m"}"
16+
COLOR_YELLOW_BG="${CANDALF_NO_COLOR:-"\\033[0;43m"}"
17+
COLOR_MAGENTA="${CANDALF_NO_COLOR:-"\\033[0;35m"}"
18+
COLOR_GREY="${CANDALF_NO_COLOR:-"\\033[0;90m"}"
19+
COLOR_END="${CANDALF_NO_COLOR:-"\\033[0;0m"}"
1920

2021
function cast() {
2122
SPELL_FILE="${1:?"SPELL_FILE not set!"}"

0 commit comments

Comments
 (0)