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>
This commit is contained in:
Y.HorieandMohammed Al Sahaf authored and GitHub committed 2026-06-04 21:41:35 -04:00
1 parent 3b7bde8f25
commit d730df2a83
1 file changed
+7 -1
+7 -1
View File
@@ -149,8 +149,14 @@ func caddyCmdToCobra(caddyCmd Command) *cobra.Command {
func WrapCommandFuncForCobra(f CommandFunc) func(cmd *cobra.Command, _ []string) error {
return func(cmd *cobra.Command, _ []string) error {
status, err := f(Flags{cmd.Flags()})
if status > 1 {
if err != nil {
// Route the error through Caddy's logger so it receives the same
// colored, structured formatting as INFO/WARN output, rather than
// cobra's plain "Error: ..." line which lacks any highlighting.
caddy.Log().Error(err.Error())
cmd.SilenceErrors = true
}
if status > 1 {
return &exitError{ExitCode: status, Err: err}
}
return err