#!/usr/bin/env bash set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${repo_root}" : "${GOCACHE:=/tmp/bat-go-cache}" export GOCACHE mapfile -t go_dirs < <(go list -f '{{.Dir}}' ./...) go_files=() for dir in "${go_dirs[@]}"; do while IFS= read -r -d '' file; do go_files+=("${file}") done < <(find "${dir}" -maxdepth 1 -type f -name '*.go' -print0) done if ((${#go_files[@]} == 0)); then exit 0 fi formatted="$(gofmt -l "${go_files[@]}")" if [[ -n "${formatted}" ]]; then printf 'gofmt required; files need formatting:\n%s\n' "${formatted}" >&2 exit 1 fi