diff options
author | Y.Horie <[email protected]> | 2023-01-22 13:28:37 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2023-01-21 21:28:37 -0700 |
commit | 5805b3ca11492c2673180e707a643b24100a9e4a (patch) | |
tree | 090c20205e5576ebb3d32ab66531dd583d84eeba /caddyconfig | |
parent | d6d7511699f6a35e3246918023af5ba3bc2cbc67 (diff) | |
download | caddy-5805b3ca11492c2673180e707a643b24100a9e4a.tar.gz caddy-5805b3ca11492c2673180e707a643b24100a9e4a.zip |
cmd: `caddy fmt` return code is 1 if not formatted (#5297)
* cmd: Fix caddy fmt if input isn't formatted
* Fixes #5294
* return exit 1 with an error message
* cmd: Use formattingDifference for caddy fmt
* #5294
* expose caddyfile.formattingDifference
Diffstat (limited to 'caddyconfig')
-rw-r--r-- | caddyconfig/caddyfile/adapter.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/caddyconfig/caddyfile/adapter.go b/caddyconfig/caddyfile/adapter.go index d5bb7c221..b924325b0 100644 --- a/caddyconfig/caddyfile/adapter.go +++ b/caddyconfig/caddyfile/adapter.go @@ -54,7 +54,7 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf // lint check: see if input was properly formatted; sometimes messy files files parse // successfully but result in logical errors (the Caddyfile is a bad format, I'm sorry) - if warning, different := formattingDifference(filename, body); different { + if warning, different := FormattingDifference(filename, body); different { warnings = append(warnings, warning) } @@ -63,10 +63,10 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf return result, warnings, err } -// formattingDifference returns a warning and true if the formatted version +// FormattingDifference returns a warning and true if the formatted version // is any different from the input; empty warning and false otherwise. // TODO: also perform this check on imported files -func formattingDifference(filename string, body []byte) (caddyconfig.Warning, bool) { +func FormattingDifference(filename string, body []byte) (caddyconfig.Warning, bool) { // replace windows-style newlines to normalize comparison normalizedBody := bytes.Replace(body, []byte("\r\n"), []byte("\n"), -1) |