Commit b9713b17 authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Add basic shell file processing.

Shell files are not normally checked, and the checking we perform
is only 'shellcheck' but that's fine for us because it gives us
a simple way to ensure that the scripts will actually do what we
expect.

However, there is currently no way to restrict the shellcheck
version to one that is known. This may need to be addressed in
the future, but for now we use the system installed version.
parent 54b6fa03
#!/bin/false /bin/bash
##
# Common functions used by the Shell code.
#
set -eo pipefail
##
# Is shell active for this action?
#
# @param $1 the action we are attempting to perform
function shell_active() {
local action="$1"
local files=''
if [[ "$action" == 'test' ]] ; then
return 1
elif [[ "$action" == 'lint' ]] ; then
files="$(config -e lint_shell_files '{shell}')"
elif [[ "$action" == 'coverage' ]] ; then
return 1
elif [[ "$action" == 'docs' ]] ; then
return 1
elif [[ "$action" == 'clean' ]] ; then
return 1
else
# Unrecognised type
return 1
fi
files="$(trim "$files")"
if [[ -n "$files" ]] ; then
return 0
fi
return 1
}
##
# Matching functions for filename expansion.
function shell_match_magic() {
echo -n 'Shell script'
}
function shell_match_extensions() {
echo -n 'sh'
}
function shell_setup_lint() {
# Do we have shelllcheck installed
if ! shellcheck -V > /dev/null 2>&1 ; then
echo "ShellCheck is not installed" >&1
exit 1
fi
}
function shell_run_lint() {
local message="Linting Shell files"
for file in $(config -e lint_shell_files '{shell}') ; do
if ! shellcheck "$file" 2>&1 \
| output_filter "$message" ; then
lint_failed=$(( lint_failed+1 ))
else
lint_passed=$(( lint_passed+1 ))
fi
message="+"
lint_total=$(( lint_total+1 ))
done
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment