Added rust support to prettybat

This commit is contained in:
Ethan P 2019-06-21 15:47:23 -07:00
parent 16ea5cc401
commit 09604dbefc
No known key found for this signature in database
GPG Key ID: 1F8DF8091CD46FBC

View File

@ -10,12 +10,13 @@ source "${LIB}/opt.sh"
source "${LIB}/str.sh"
source "${LIB}/print.sh"
# -----------------------------------------------------------------------------
PROGRAM="$0"
# -----------------------------------------------------------------------------
# Formatters:
# -----------------------------------------------------------------------------
FORMATTERS=("prettier")
FORMATTERS=("prettier" "rustfmt")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -39,6 +40,19 @@ formatter_prettier_process() {
return $?
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
formatter_rustfmt_supports() {
[[ "$1" = ".rs" ]]
return $?
}
formatter_rustfmt_process() {
rustfmt
return $?
}
# -----------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------
@ -62,6 +76,7 @@ map_language_to_extension() {
json) ext=".json" ;;
md|mdown|markdown) ext=".md" ;;
yaml|yml) ext=".yml" ;;
rust|rs) ext=".rs" ;;
esac
echo "$ext"
@ -120,14 +135,14 @@ process_file() {
data_raw="$(cat -)"
data_formatted="$("formatter_${formatter}_process" "$file" 2>/dev/null <<< "$data_raw")"
if [[ $? -ne 0 ]]; then
printc "{YELLOW}[%s warning]{CLEAR}: 'STDIN': Unable to format with '%s'" "$0" "$formatter" 1>&2
printc "%{YELLOW}[%s warning]%{CLEAR}: 'STDIN': Unable to format with '%s'\n" "$PROGRAM" "$formatter" 1>&2
print_file --language="$lang" - <<< "$data_raw"
return 1
fi
else
data_formatted="$("formatter_${formatter}_process" "$file" < "$file")"
if [[ $? -ne 0 ]]; then
printc "{YELLOW}[%s warning]{CLEAR}: '%s': Unable to format with '%s'" "$0" "$file" "$formatter" 1>&2
printc "%{YELLOW}[%s warning]%{CLEAR}: '%s': Unable to format with '%s'\n" "$PROGRAM" "$file" "$formatter" 1>&2
print_file --language="$lang" "$file"
return 1
fi