mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 14:35:48 +03:00
3b846bae6e
Squashed commit of the following:
commit 5cc2914b18fd71ff83e2872ef6755f2ff56d653c
Merge: bf14a513e 085b4fdce
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 7 14:58:44 2023 +0300
Merge branch 'master' into upd-proj-skel
commit bf14a513eb46ebf2c2809246603b071e6c334e9f
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 7 14:47:10 2023 +0300
all: imp code
commit ec3f7a88b86b3f423193aa95c2e820bcd86fdef3
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 7 14:28:39 2023 +0300
scripts: upd go lint
commit 6a9342f6058bc21252f97045f7015440f013cb09
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 7 14:13:17 2023 +0300
all: upd proj skel
84 lines
1.6 KiB
Bash
84 lines
1.6 KiB
Bash
#!/bin/sh
|
|
|
|
# Common script helpers
|
|
#
|
|
# This file contains common script helpers. It should be sourced in scripts
|
|
# right after the initial environment processing.
|
|
|
|
# This comment is used to simplify checking local copies of the script. Bump
|
|
# this number every time a remarkable change is made to this script.
|
|
#
|
|
# AdGuard-Project-Version: 3
|
|
|
|
|
|
|
|
# Deferred helpers
|
|
|
|
not_found_msg='
|
|
looks like a binary not found error.
|
|
make sure you have installed the linter binaries using:
|
|
|
|
$ make go-tools
|
|
'
|
|
readonly not_found_msg
|
|
|
|
not_found() {
|
|
if [ "$?" -eq '127' ]
|
|
then
|
|
# Code 127 is the exit status a shell uses when a command or a file is
|
|
# not found, according to the Bash Hackers wiki.
|
|
#
|
|
# See https://wiki.bash-hackers.org/dict/terms/exit_status.
|
|
echo "$not_found_msg" 1>&2
|
|
fi
|
|
}
|
|
trap not_found EXIT
|
|
|
|
|
|
|
|
# Helpers
|
|
|
|
# run_linter runs the given linter with two additions:
|
|
#
|
|
# 1. If the first argument is "-e", run_linter exits with a nonzero exit code
|
|
# if there is anything in the command's combined output.
|
|
#
|
|
# 2. In any case, run_linter adds the program's name to its combined output.
|
|
run_linter() (
|
|
set +e
|
|
|
|
if [ "${VERBOSE:-0}" -lt '2' ]
|
|
then
|
|
set +x
|
|
fi
|
|
|
|
cmd="${1:?run_linter: provide a command}"
|
|
shift
|
|
|
|
exit_on_output='0'
|
|
if [ "$cmd" = '-e' ]
|
|
then
|
|
exit_on_output='1'
|
|
cmd="${1:?run_linter: provide a command}"
|
|
shift
|
|
fi
|
|
|
|
readonly cmd
|
|
|
|
output="$( "$cmd" "$@" )"
|
|
exitcode="$?"
|
|
|
|
readonly output
|
|
|
|
if [ "$output" != '' ]
|
|
then
|
|
echo "$output" | sed -e "s/^/${cmd}: /"
|
|
|
|
if [ "$exitcode" -eq '0' ] && [ "$exit_on_output" -eq '1' ]
|
|
then
|
|
exitcode='1'
|
|
fi
|
|
fi
|
|
|
|
return "$exitcode"
|
|
)
|