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>
pull/7802/head
Y.Horie 2026-06-05 10:41:35 +09:00 committed by GitHub
parent 3b7bde8f25
commit d730df2a83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

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