github.com/prebid/prebid-server/v2@v2.18.0/scripts/format.sh (about) 1 #!/bin/bash 2 3 die() { echo -e "$@" 1>&2 ; exit 1; } 4 5 AUTOFMT=true 6 while getopts 'f:' OPTION; do 7 case "$OPTION" in 8 f) 9 AUTOFMT="$OPTARG" 10 ;; 11 esac 12 done 13 14 # Build a list of all the top-level directories in the project. 15 for DIRECTORY in */ ; do 16 GOGLOB="$GOGLOB ${DIRECTORY%/}" 17 done 18 GOGLOB="${GOGLOB/ docs/}" 19 GOGLOB="${GOGLOB/ vendor/}" 20 21 # Check that there are no formatting issues 22 GOFMT_LINES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | wc -l | xargs` 23 if $AUTOFMT; then 24 # if there are files with formatting issues, they will be automatically corrected using the gofmt -w <file> command 25 if [[ $GOFMT_LINES -ne 0 ]]; then 26 FMT_FILES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | xargs` 27 for FILE in $FMT_FILES; do 28 echo "Running: gofmt -s -w $FILE" 29 `gofmt -s -w $FILE` 30 done 31 fi 32 else 33 test $GOFMT_LINES -eq 0 || die "gofmt needs to be run, ${GOFMT_LINES} files have issues. Below is a list of files to review:\n`gofmt -s -l $GOGLOB`" 34 fi