From 8c0b49bf039bc0b6ab72b44ef0e1e6587c76ad2b Mon Sep 17 00:00:00 2001 From: Amis Shokoohi Date: Tue, 31 Jan 2023 19:54:44 +0330 Subject: cmd: `fmt` exit successfully after overwriting config file (#5351) Fixes https://github.com/caddyserver/caddy/issues/5349 --- cmd/commandfuncs.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go index bc4c227..c5264ed 100644 --- a/cmd/commandfuncs.go +++ b/cmd/commandfuncs.go @@ -558,7 +558,10 @@ func cmdFmt(fl Flags) (int, error) { if err := os.WriteFile(formatCmdConfigFile, output, 0600); err != nil { return caddy.ExitCodeFailedStartup, fmt.Errorf("overwriting formatted file: %v", err) } - } else if fl.Bool("diff") { + return caddy.ExitCodeSuccess, nil + } + + if fl.Bool("diff") { diff := difflib.Diff( strings.Split(string(input), "\n"), strings.Split(string(output), "\n")) -- cgit v1.2.3