Skip to content

Commit

Permalink
[lib] Use function exec_cmd from lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
shizunge committed Jan 23, 2024
1 parent 8959491 commit 4ae2eae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/dns-lists-downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,7 @@ download_from_single_source_file() {
continue
fi
fix_list "${CURRENT_FILE}"
if [ -n "${POST_DOWNLOAD_CMD}" ]; then
local LOG=
log INFO "Run POST_DOWNLOAD_CMD: ${POST_DOWNLOAD_CMD} ${CURRENT_FILE}"
if LOG=$(eval "${POST_DOWNLOAD_CMD} ${CURRENT_FILE}" 2>&1); then
echo "${LOG}" | log_lines INFO
else
log WARN "POST_DOWNLOAD_CMD: \"${POST_DOWNLOAD_CMD} ${CURRENT_FILE}\" returned a non-zero value ${?}."
echo "${LOG}" | log_lines WARN
fi
fi
exec_cmd "post-download" "${POST_DOWNLOAD_CMD} ${CURRENT_FILE}"
log DEBUG "Merging ${CURRENT_FILE} to ${ACCUMULATOR_FILE}"
# SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects.
# shellcheck disable=SC2129
Expand Down
21 changes: 21 additions & 0 deletions src/lib-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,27 @@ read_env() {
return 0
}

exec_cmd() {
local TAG="${1}"; shift;
local CMD="${*}"
[ -z "${CMD}" ] && return 0
local OLD_LOG_SCOPE="${LOG_SCOPE}"
export LOG_SCOPE="${OLD_LOG_SCOPE} ${TAG}"
local LOG=
local RT=0
log INFO "Run ${TAG} command: ${CMD}"
if LOG=$(eval "${CMD}"); then
echo "${LOG}" | log_lines INFO
else
RT=$?
echo "${LOG}" | log_lines WARN
log WARN "${TAG} command returned a non-zero value ${RT}."
fi
log INFO "Finish ${TAG} command."
export LOG_SCOPE="${OLD_LOG_SCOPE}"
return "${RT}"
}

swarm_network_arguments() {
if [ -z "${NETWORK_NAME}" ]; then
echo ""
Expand Down

0 comments on commit 4ae2eae

Please sign in to comment.