fix something

This commit is contained in:
Ing 2024-02-28 17:10:38 +08:00
parent 62cf264b18
commit 36e11478c4
2 changed files with 9 additions and 9 deletions

View File

@ -3,7 +3,7 @@
# 1 - Path of Key # 1 - Path of Key
# 2 - Path of yaml config file # 2 - Path of yaml config file
function deleteConfigKey() { function deleteConfigKey() {
yq eval 'del(.'${1}')' --inplace "${2}" yq eval 'del(.'${1}')' --inplace "${2}" 2>/dev/null
} }
############################################################################### ###############################################################################
@ -12,7 +12,7 @@ function deleteConfigKey() {
# 2 - Value # 2 - Value
# 3 - Path of yaml config file # 3 - Path of yaml config file
function writeConfigKey() { function writeConfigKey() {
[ "${2}" = "{}" ] && yq eval '.'${1}' = {}' --inplace "${3}" || yq eval '.'${1}' = "'"${2}"'"' --inplace "${3}" [ "${2}" = "{}" ] && yq eval '.'${1}' = {}' --inplace "${3}" 2>/dev/null || yq eval '.'${1}' = "'"${2}"'"' --inplace "${3}" 2>/dev/null
} }
############################################################################### ###############################################################################
@ -21,7 +21,7 @@ function writeConfigKey() {
# 2 - Path of yaml config file # 2 - Path of yaml config file
# Return Value # Return Value
function readConfigKey() { function readConfigKey() {
RESULT=$(yq eval '.'${1}' | explode(.)' "${2}") RESULT=$(yq eval '.'${1}' | explode(.)' "${2}" 2>/dev/null)
[ "${RESULT}" == "null" ] && echo "" || echo ${RESULT} [ "${RESULT}" == "null" ] && echo "" || echo ${RESULT}
} }
@ -40,7 +40,7 @@ function initConfigKey() {
# 2 - Path of yaml config file # 2 - Path of yaml config file
# Returns map of values # Returns map of values
function readConfigMap() { function readConfigMap() {
yq eval '.'${1}' | explode(.) | to_entries | map([.key, .value] | join(": ")) | .[]' "${2}" yq eval '.'${1}' | explode(.) | to_entries | map([.key, .value] | join(": ")) | .[]' "${2}" 2>/dev/null
} }
############################################################################### ###############################################################################
@ -49,7 +49,7 @@ function readConfigMap() {
# 2 - Path of yaml config file # 2 - Path of yaml config file
# Returns array/map of values # Returns array/map of values
function readConfigArray() { function readConfigArray() {
yq eval '.'${1}'[]' "${2}" yq eval '.'${1}'[]' "${2}" 2>/dev/null
} }
############################################################################### ###############################################################################
@ -58,5 +58,5 @@ function readConfigArray() {
# 2 - Path of yaml config file # 2 - Path of yaml config file
# Returns array of values # Returns array of values
function readConfigEntriesArray() { function readConfigEntriesArray() {
yq eval '.'${1}' | explode(.) | to_entries | map([.key])[] | .[]' "${2}" yq eval '.'${1}' | explode(.) | to_entries | map([.key])[] | .[]' "${2}" 2>/dev/null
} }

View File

@ -10,7 +10,7 @@
# 2 - Key # 2 - Key
# Return Value # Return Value
function readModelKey() { function readModelKey() {
readConfigKey "${2}" "${WORK_PATH}/model-configs/${1}.yml" readConfigKey "${2}" "${WORK_PATH}/model-configs/${1}.yml" 2>/dev/null
} }
############################################################################### ###############################################################################
@ -19,7 +19,7 @@ function readModelKey() {
# 2 - Path of key # 2 - Path of key
# Returns map of values # Returns map of values
function readModelMap() { function readModelMap() {
readConfigMap "${2}" "${WORK_PATH}/model-configs/${1}.yml" readConfigMap "${2}" "${WORK_PATH}/model-configs/${1}.yml" 2>/dev/null
} }
############################################################################### ###############################################################################
@ -28,7 +28,7 @@ function readModelMap() {
# 2 - Path of key # 2 - Path of key
# Returns array/map of values # Returns array/map of values
function readModelArray() { function readModelArray() {
readConfigArray "${2}" "${WORK_PATH}/model-configs/${1}.yml" readConfigArray "${2}" "${WORK_PATH}/model-configs/${1}.yml" 2>/dev/null
} }
############################################################################### ###############################################################################