brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: caddy fmt --diff shows what a Caddyfile cleanup would change

CLI
~/tips/tip-caddy-fmt-diff-check

caddy fmt --diff Caddyfile

Compares a Caddyfile with its formatted version and shows the differences, without touching the file.

Caddyfiles get messy fast once a few people have edited them. Caddy ships its own formatter, so nobody has to fix indentation by eye.

caddy fmt --diff Caddyfile

The docs say caddy fmt formats or prettifies a Caddyfile and then exits. By default the result is printed to the terminal. With --diff (short form -d) the output is compared against the input, and lines are prefixed with - and + where they differ. So you see the change before you accept it.

When the diff looks fine, write it back:

caddy fmt --overwrite Caddyfile

The short form is -w. With --overwrite the result goes into the input file instead of the terminal. If you leave out the path, Caddy assumes a file named Caddyfile in the current directory. A path of - reads from stdin.

The detail I like most is the exit code. The docs say the command exits with code 1 if there are any differences. That makes it usable as a check in a script:

caddy fmt --diff Caddyfile || echo "Caddyfile needs formatting"

The caveat is that --overwrite really does rewrite your file. Keep the Caddyfile in version control, or at least look at the --diff output first.

Further reading: Caddy command line reference

Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link