Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 09:45 UTC
cmd: colored error message in WrapCommandFuncForCobra (#7760) (#7768)
Signed-off-by: Y.Horie <u5.horie@gmail.com> Co-authored-by: Mohammed Al Sahaf <msaa1990@gmail.com>
Y.Horie committed
Jun 5, 2026 at 10:41 UTC
d730df2a83e83ea3ec2990b213385cc34152c62e
1 file changed
+7
-1
cmd/cobra.go
+7
-1
@@ -149,8 +149,14 @@ func caddyCmdToCobra(caddyCmd Command) *cobra.Command {
149
func WrapCommandFuncForCobra(f CommandFunc) func(cmd *cobra.Command, _ []string) error {
150
return func(cmd *cobra.Command, _ []string) error {
151
status, err := f(Flags{cmd.Flags()})
152
- if status > 1 {
152
+ if err != nil {
153
+ // Route the error through Caddy's logger so it receives the same
154
+ // colored, structured formatting as INFO/WARN output, rather than
155
+ // cobra's plain "Error: ..." line which lacks any highlighting.
156
+ caddy.Log().Error(err.Error())
157
cmd.SilenceErrors = true
158
+ }
159
+ if status > 1 {
160
return &exitError{ExitCode: status, Err: err}
161
}
162
return err