Add check-file-in-alphabetical-order for cleanup

Both verify-golint.sh and verify-shellcheck.sh have the same logic
which checks failure_file in alphabetical order.
In addition, we'd like to add another script which requires the
same logic. So this add a common function for cleanup.
This commit is contained in:
Kenichi Omichi
2019-01-26 02:04:00 +00:00
parent 5673506540
commit c32d1acbb9
3 changed files with 21 additions and 20 deletions

View File

@@ -781,6 +781,23 @@ function kube::util::ensure-gnu-sed {
fi
}
# kube::util::check-file-in-alphabetical-order <file>
# Check that the file is in alphabetical order
#
function kube::util::check-file-in-alphabetical-order {
local failure_file="$1"
if ! diff -u "${failure_file}" <(LC_ALL=C sort "${failure_file}"); then
{
echo
echo "${failure_file} is not in alphabetical order. Please sort it:"
echo
echo " LC_ALL=C sort -o ${failure_file} ${failure_file}"
echo
} >&2
false
fi
}
# Some useful colors.
if [[ -z "${color_start-}" ]]; then
declare -r color_start="\033["