Debian Codegraph @

util/common.bash

raw symbols SCIP
1 # Copyright 2025 The go-yaml Project Contributors
2 # SPDX-License-Identifier: Apache-2.0
3
4 # Use strict settings:
5 set -euo pipefail
6
7 # ANSI color code vars:
8 RED="\e[1;31m"
9 RESET="\e[0m"
10
11 require-bash-4.4+() {
12 if ! shopt -s compat43 2>/dev/null; then
13 local bash version
14 bash=$(command -v bash)
15 version=$("$bash" -c "echo \$BASH_VERSION")
16
17 cat <<-... >&2
18 Error: 'bash' version 4.4+ is required to be first in your PATH.
19
20 You currently have:
21 $bash
22 $version
23 ...
24
25 exit 1
26 fi
27
28 # inherit_errexit is important and introduced in 4.4
29 shopt -s inherit_errexit
30 }
31
32 require-commands() (
33 for cmd; do
34 command -v "$cmd" >/dev/null ||
35 die "Error: $cmd is not installed or available in the PATH."
36 done
37 )
38
39 # General error function:
40 die() {
41 echo -e "$RED$1$RESET" >&2
42 shift
43
44 for line; do
45 echo -e "$line"
46 done >&2
47
48 exit 1
49 }