script/check-config: disable colors

...when the stdout is not a terminal, and also when NO_COLOR environment
variable is set to any non-empty value (as per no-color.org).

Co-authored-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2023-12-19 17:26:35 -08:00
parent b94b559058
commit 6aa4c1a13e
+4
View File
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -e -u
[ -t 1 ] || NO_COLOR=1
# bits of this were adapted from check_config.sh in docker
# see also https://github.com/docker/docker/blob/master/contrib/check-config.sh
@@ -43,6 +45,8 @@ is_set_as_module() {
}
color() {
[ -n "${NO_COLOR:-}" ] && return
local codes=()
if [ "$1" = 'bold' ]; then
codes=("${codes[@]-}" '1')