cmd: fmt exit successfully after overwriting config file (#5351)

Fixes https://github.com/caddyserver/caddy/issues/5349
This commit is contained in:
Amis Shokoohi 2023-01-31 19:54:44 +03:30 committed by GitHub
parent 201b9b41f9
commit 8c0b49bf03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"))