github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/utils/repofmt/format_repo.sh (about)

     1  #!/bin/bash
     2  
     3  set -eo pipefail
     4  
     5  script_dir=$(dirname "$0")
     6  cd $script_dir/../..
     7  
     8  paths=`find . -maxdepth 1 -mindepth 1 \( -name gen -prune -o -type d -print -o -type f -name '*.go' -print \)`
     9  
    10  goimports -w -local github.com/dolthub/dolt $paths
    11  
    12  bad_files=$(find $paths -name '*.go' | while read f; do
    13      if [[ $(awk '/import \(/{flag=1;next}/\)/{flag=0}flag' < $f | egrep -c '$^') -gt 2 ]]; then
    14          echo $f
    15      fi
    16  done)
    17  
    18  if [ "$bad_files" != "" ]; then
    19      for f in $bad_files; do
    20          awk '/import \(/{flag=1}/\)/{flag=0}flag&&!/^$/||!flag' < "$f" > "$f.bak"
    21          mv "$f.bak" "$f"
    22      done
    23      goimports -w -local github.com/dolthub/dolt .
    24  fi