Create and use gofmt.sh wrapper script
This commit is contained in:
52
gofmt.sh
Executable file
52
gofmt.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -uo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
source "$DIR/_reformat-common.bash"
|
||||
|
||||
set -e
|
||||
|
||||
file="$1"
|
||||
|
||||
pushd "$(dirname "$file")" 2>&1
|
||||
|
||||
wrflog hello
|
||||
|
||||
if [[ "$WOULD_REFORMAT" = "would_reformat" ]]; then
|
||||
success_retval=0
|
||||
would_reformat_retval=1
|
||||
syntax_error_retval=2
|
||||
|
||||
set +e
|
||||
out=$(gofmt -l "$file")
|
||||
exitval="$?"
|
||||
set -e
|
||||
|
||||
wrflog out: "$out"
|
||||
|
||||
if [[ "$exitval" = "$syntax_error_retval" ]]; then
|
||||
retval="$exitval"
|
||||
elif [[ "$out" = "$file" ]]; then
|
||||
retval="$would_reformat_retval"
|
||||
else
|
||||
# success
|
||||
retval="$exitval"
|
||||
fi
|
||||
|
||||
echo "$out"
|
||||
exit "$retval"
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$WOULD_REFORMAT" = "do_reformat" ]]; then
|
||||
out=$(npx prettier --write "$file" 2>&1 >/dev/null)
|
||||
retval="$?"
|
||||
|
||||
echo "$out"
|
||||
exit "$retval"
|
||||
fi
|
||||
|
||||
exit 255
|
||||
Reference in New Issue
Block a user