Skip to content

Commit 39997aa

Browse files
committed
[update] : Use common function to use msg.sh
1 parent c12fd90 commit 39997aa

1 file changed

Lines changed: 17 additions & 33 deletions

File tree

build.sh

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,61 +42,45 @@ fi
4242

4343
umask 0022
4444

45+
# Message common function
46+
# msg_common [type] [-n] [string]
47+
msg_common(){
48+
local _msg_opts=("-a" "build.sh") _type="${1}"
49+
shift 1
50+
[[ "${1}" = "-n" ]] && _msg_opts+=("-o" "-n") && shift 1
51+
[[ "${msgdebug}" = true ]] && _msg_opts+=("-x")
52+
[[ "${nocolor}" = true ]] && _msg_opts+=("-n")
53+
_msg_opts+=("${_type}" "${@}")
54+
"${tools_dir}/msg.sh" "${_msg_opts[@]}"
55+
}
56+
4557
# Show an INFO message
4658
# ${1}: message string
4759
msg_info() {
48-
local _msg_opts="-a build.sh"
49-
if [[ "${1}" = "-n" ]]; then
50-
_msg_opts="${_msg_opts} -o -n"
51-
shift 1
52-
fi
53-
[[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
54-
[[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
55-
"${tools_dir}/msg.sh" ${_msg_opts} info "${1}"
60+
msg_common info "${@}"
5661
}
5762

5863
# Show an Warning message
5964
# ${1}: message string
6065
msg_warn() {
61-
local _msg_opts="-a build.sh"
62-
if [[ "${1}" = "-n" ]]; then
63-
_msg_opts="${_msg_opts} -o -n"
64-
shift 1
65-
fi
66-
[[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
67-
[[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
68-
"${tools_dir}/msg.sh" ${_msg_opts} warn "${1}"
66+
msg_common warn "${@}"
6967
}
7068

7169
# Show an debug message
7270
# ${1}: message string
7371
msg_debug() {
7472
if [[ "${debug}" = true ]]; then
75-
local _msg_opts="-a build.sh"
76-
if [[ "${1}" = "-n" ]]; then
77-
_msg_opts="${_msg_opts} -o -n"
78-
shift 1
79-
fi
80-
[[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
81-
[[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
82-
"${tools_dir}/msg.sh" ${_msg_opts} debug "${1}"
73+
msg_common debug "${@}"
8374
fi
8475
}
8576

8677
# Show an ERROR message then exit with status
8778
# ${1}: message string
8879
# ${2}: exit code number (with 0 does not exit)
8980
msg_error() {
90-
local _msg_opts="-a build.sh"
91-
if [[ "${1}" = "-n" ]]; then
92-
_msg_opts="${_msg_opts} -o -n"
93-
shift 1
94-
fi
95-
[[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x"
96-
[[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n"
97-
"${tools_dir}/msg.sh" ${_msg_opts} error "${1}"
81+
msg_common error "${@}"
9882
if [[ -n "${2:-}" ]]; then
99-
exit ${2}
83+
exit "${2}"
10084
fi
10185
}
10286

0 commit comments

Comments
 (0)