aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Prokoschenko <nikolai@prokoschenko.de>2023-02-19 02:00:08 +0100
committerGitHub <noreply@github.com>2023-02-18 17:00:08 -0800
commit972b9906bf6d23f5a8e92129a4572a906bdfe45e (patch)
tree05b5fa2bb5b6e89e3664b86ddf9fd00386c398e5
parent4f2e4cd925d479904ab18c73613893ebac1b58b9 (diff)
Add formatter for Caddyfile (#154)
Add formatter for Caddyfile (#136)
-rw-r--r--CHANGELOG.md4
-rw-r--r--apheleia.el2
-rw-r--r--test/formatters/installers/caddyfmt.bash18
-rw-r--r--test/formatters/samplecode/caddyfmt/in.caddyfile14
-rw-r--r--test/formatters/samplecode/caddyfmt/out.caddyfile14
5 files changed, 32 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6692d8d..00ab534 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,9 +42,13 @@ The format is based on [Keep a Changelog].
* [gofumpt](https://pkg.go.dev/mvdan.cc/gofumpt) and
[goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) for
[Go](https://golang.google.cn/) ([#147]).
+* [`caddy fmt`](https://caddyserver.com/docs/command-line#caddy-fmt)
+ for [Caddyfile](https://caddyserver.com/docs/caddyfile), used by
+ [Caddy 2](https://caddyserver.com/) ([#136])
[#131]: https://github.com/radian-software/apheleia/issues/131
[#134]: https://github.com/radian-software/apheleia/issues/134
+[#136]: https://github.com/radian-software/apheleia/issues/136
[#137]: https://github.com/radian-software/apheleia/pull/137
[#138]: https://github.com/radian-software/apheleia/pull/138
[#143]: https://github.com/radian-software/apheleia/pull/143
diff --git a/apheleia.el b/apheleia.el
index 3a847b6..7eccb1f 100644
--- a/apheleia.el
+++ b/apheleia.el
@@ -941,6 +941,7 @@ being run, for diagnostic purposes."
'((bean-format . ("bean-format"))
(black . ("black" "-"))
(brittany . ("brittany"))
+ (caddyfmt . ("caddy" "fmt" "-"))
(clang-format . ("clang-format"
"-assume-filename"
(or (buffer-file-name)
@@ -1133,6 +1134,7 @@ function: %s" command)))
(bash-ts-mode . shfmt)
(beancount-mode . bean-format)
(c++-ts-mode . clang-format)
+ (caddyfile-mode . caddyfmt)
(cc-mode . clang-format)
(c-mode . clang-format)
(c-ts-mode . clang-format)
diff --git a/test/formatters/installers/caddyfmt.bash b/test/formatters/installers/caddyfmt.bash
new file mode 100644
index 0000000..e311980
--- /dev/null
+++ b/test/formatters/installers/caddyfmt.bash
@@ -0,0 +1,18 @@
+ver="$(latest_release caddyserver/caddy)"
+
+arch="$(uname -m)"
+case "${arch}" in
+ "x86_64")
+ arch="amd64"
+ ;;
+ "aarch64")
+ arch="arm64"
+ ;;
+ *)
+ echo >&2 "unsupported architecture: ${arch}"
+ exit 1
+ ;;
+esac
+
+curl -L -s "https://github.com/caddyserver/caddy/releases/download/${ver}/caddy_$(echo $ver | sed 's|^v||g')_linux_${arch}.tar.gz" | \
+ tar zxv -C /usr/local/bin/ caddy
diff --git a/test/formatters/samplecode/caddyfmt/in.caddyfile1 b/test/formatters/samplecode/caddyfmt/in.caddyfile1
new file mode 100644
index 0000000..b971d56
--- /dev/null
+++ b/test/formatters/samplecode/caddyfmt/in.caddyfile1
@@ -0,0 +1,4 @@
+example.com {
+ root * /var/www
+ file_server
+}
diff --git a/test/formatters/samplecode/caddyfmt/out.caddyfile1 b/test/formatters/samplecode/caddyfmt/out.caddyfile1
new file mode 100644
index 0000000..d4d6bc0
--- /dev/null
+++ b/test/formatters/samplecode/caddyfmt/out.caddyfile1
@@ -0,0 +1,4 @@
+example.com {
+ root * /var/www
+ file_server
+}