mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 19:57:46 +02:00
prettybat: Use yq
for YAML and JSON pretty formatting
This commit is contained in:
parent
32706dd581
commit
47cfb9ec73
@ -24,7 +24,7 @@ hook_version
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
FORMATTERS=(
|
FORMATTERS=(
|
||||||
"prettier" "rustfmt" "shfmt" "clangformat"
|
"yq" "prettier" "rustfmt" "shfmt" "clangformat"
|
||||||
"black" "mix_format" "column"
|
"black" "mix_format" "column"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -171,6 +171,46 @@ formatter_column_process() {
|
|||||||
{ { "$needs_newline" && sed 's/$/\n/'; } || cat; } | column "${args[@]}"
|
{ { "$needs_newline" && sed 's/$/\n/'; } || cat; } | column "${args[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
formatter_yq_supports__version_ok() {
|
||||||
|
local yq_version
|
||||||
|
yq_version=$(yq --version | sed 's/^.* version v//')
|
||||||
|
|
||||||
|
# If it's older than yq version 4, replace the functions to save processing.
|
||||||
|
if version_compare "$yq_version" -lt 4.0; then
|
||||||
|
formatter_yq_supports() { return 1; }
|
||||||
|
formatter_yq_supports__version_ok() { return 1; }
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# It's supported.
|
||||||
|
formatter_yq_supports__version_ok() { return 0; }
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter_yq_supports() {
|
||||||
|
case "$1" in
|
||||||
|
.yaml | yml | \
|
||||||
|
.json)
|
||||||
|
formatter_yq_supports__version_ok
|
||||||
|
return $?
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter_yq_process() {
|
||||||
|
local args=()
|
||||||
|
case "$1" in
|
||||||
|
*.json) args+=(--output-format json) ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
yq --prettyPrint --indent 2 "${args[@]}"
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Functions:
|
# Functions:
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user