Move wrapper selection into a function
This commit is contained in:
@@ -165,6 +165,34 @@ function sniff_file_type() {
|
|||||||
echo $file_type
|
echo $file_type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function choose_wrapper() {
|
||||||
|
file_type="$1"
|
||||||
|
|
||||||
|
if [[ $file_type = "javascript" ||
|
||||||
|
$file_type = "vue" ||
|
||||||
|
$file_type = "typescript" ||
|
||||||
|
$file_type = "css" ||
|
||||||
|
$file_type = "php" ||
|
||||||
|
$file_type = "html" ||
|
||||||
|
$file_type = "jsx" ||
|
||||||
|
$file_type = "tsx" ||
|
||||||
|
$file_type == "css" ||
|
||||||
|
$file_type == "scss" ||
|
||||||
|
$file_type = "sh" ]]; then
|
||||||
|
out="$WF_ROOT"/./prettier.sh
|
||||||
|
elif [[ $file_type == "python" ]]; then
|
||||||
|
out="$WF_ROOT"/./isort-and-black.sh
|
||||||
|
elif [[ $file_type == "golang" ]]; then
|
||||||
|
out="$WF_ROOT"/./gofmt.sh
|
||||||
|
elif [[ $file_type == "dart" ]]; then
|
||||||
|
out="$WF_ROOT"/./dart_format.sh
|
||||||
|
else
|
||||||
|
out="$WF_ROOT"/./default.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$out"
|
||||||
|
}
|
||||||
|
|
||||||
function wrflog() {
|
function wrflog() {
|
||||||
echo "$@" >>/tmp/wrflog
|
echo "$@" >>/tmp/wrflog
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "ignoring"
|
echo -n "unhandled file type; ignoring"
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -22,41 +22,12 @@ file_type=$(sniff_file_type "$file")
|
|||||||
|
|
||||||
export WOULD_REFORMAT=would_reformat
|
export WOULD_REFORMAT=would_reformat
|
||||||
|
|
||||||
if [[ $file_type = "javascript" ||
|
wrapper=$(choose_wrapper "$file_type")
|
||||||
$file_type = "vue" ||
|
|
||||||
$file_type = "typescript" ||
|
|
||||||
$file_type = "css" ||
|
|
||||||
$file_type = "php" ||
|
|
||||||
$file_type = "html" ||
|
|
||||||
$file_type = "js" ||
|
|
||||||
$file_type = "ts" ||
|
|
||||||
$file_type == "css" ||
|
|
||||||
$file_type == "scss" ||
|
|
||||||
$file_type = "sh" ]]; then
|
|
||||||
set +e
|
|
||||||
out=$("$WF_ROOT"/./prettier.sh "$file" 2>&1 >/dev/null)
|
|
||||||
retval="$?"
|
|
||||||
set -e
|
|
||||||
elif [[ $file_type == "python" ]]; then
|
|
||||||
set +e
|
|
||||||
out=$("$WF_ROOT"/./isort-and-black.sh "$file" 2>&1 >/dev/null)
|
|
||||||
retval="$?"
|
|
||||||
set -e
|
|
||||||
elif [[ $file_type == "golang" ]]; then
|
|
||||||
set +e
|
|
||||||
out=$("$WF_ROOT"/./gofmt.sh "$file")
|
|
||||||
retval="$?"
|
|
||||||
set -e
|
|
||||||
elif [[ $file_type == "dart" ]]; then
|
|
||||||
set +e
|
|
||||||
out=$("$WF_ROOT"/./dart_format.sh "$file")
|
|
||||||
retval="$?"
|
|
||||||
set -e
|
|
||||||
else
|
|
||||||
echo -n "ignoring"
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
fi
|
set +e
|
||||||
|
out=$("$wrapper" "$file" 2>&1 >/dev/null)
|
||||||
|
retval="$?"
|
||||||
|
set -e
|
||||||
|
|
||||||
success_retval=0
|
success_retval=0
|
||||||
would_reformat_retval=1
|
would_reformat_retval=1
|
||||||
|
|||||||
Reference in New Issue
Block a user