Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Assure that get_json_array outputs compact json output #280

Merged
merged 1 commit into from
Dec 1, 2024
Merged
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
34 changes: 17 additions & 17 deletions scripts/exports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# 2. jq query
# 3. Module config content
get_yaml_array() {
local -n arr=$1
local jq_query=$2
local module_config=$3
local -n arr="${1}"
local jq_query="${2}"
local module_config="${3}"

if [[ -z $jq_query || -z $module_config ]]; then
if [[ -z "${jq_query}" || -z "${module_config}" ]]; then
echo "Usage: get_yaml_array VARIABLE_TO_STORE_RESULTS JQ_QUERY MODULE_CONFIG" >&2
return 1
fi

readarray -t arr < <(echo "$module_config" | yq -I=0 "$jq_query")
readarray -t arr < <(echo "${module_config}" | yq -I=0 "${jq_query}")
}

# Function to retrieve module configs and populate an array
Expand All @@ -24,28 +24,28 @@ get_yaml_array() {
# 2. jq query
# 3. Module config content
get_json_array() {
local -n arr=$1
local jq_query=$2
local module_config=$3
local -n arr="${1}"
local jq_query="${2}"
local module_config="${3}"

if [[ -z $jq_query || -z $module_config ]]; then
if [[ -z "${jq_query}" || -z "${module_config}" ]]; then
echo "Usage: get_json_array VARIABLE_TO_STORE_RESULTS JQ_QUERY MODULE_CONFIG" >&2
return 1
fi

readarray -t arr < <(echo "$module_config" | jq -r "$jq_query")
readarray -t arr < <(echo "${module_config}" | jq -c -r "${jq_query}")
}

color_string() {
local string="$1"
local color_code="$2"
local string="${1}"
local color_code="${2}"
local reset_code="\033[0m"

# ANSI color codes: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
# Example color codes: 31=red, 32=green, 33=yellow, 34=blue, 35=magenta, 36=cyan, 37=white

# Check if color code is provided, otherwise default to white (37)
if [[ -z "$color_code" ]]; then
if [[ -z "${color_code}" ]]; then
color_code="37"
fi

Expand All @@ -58,13 +58,13 @@ color_string() {
echo -e "\033[${color_code}m${string}${reset_code}"
else
# Output is not a TTY: Do not apply color codes
echo "$string"
echo "${string}"
fi
}

# Parse OS version and export it
export OS_VERSION=$(grep -Po "(?<=VERSION_ID=)\d+" /usr/lib/os-release)
export OS_ARCH=$(uname -m)
export OS_VERSION="$(grep -Po "(?<=VERSION_ID=)\d+" /usr/lib/os-release)"
export OS_ARCH="$(uname -m)"

# Export functions for use in sub-shells or sourced scripts
export -f get_yaml_array
Expand Down
Loading