feat: console help, examples and named loggers (SummerCMS v0.4.0)

Every command gets long help and examples, descriptions in imperative
sentence case, and a warn-only TestCommandsDocumented over bonfire.CheckDocs.
The plugin logs through a diary component logger instead of the process
default logger. Requires SummerCMS v0.4.0; command names and flags unchanged.
This commit is contained in:
Jakub Zych
2026-10-21 17:37:34 +02:00
parent 2efe3514a8
commit b3cc9784de
7 changed files with 156 additions and 5 deletions

View File

@@ -4,7 +4,6 @@ package api
import (
"errors"
"fmt"
"log/slog"
"net/http"
"regexp"
@@ -62,7 +61,7 @@ func Show(app *backpack.App) http.HandlerFunc {
db = db.WithContext(r.Context())
locale, err := findLocale(db, r.URL.Query().Get("locale"))
if err != nil {
slog.Default().Error("faq api: locale", "error", err)
pluginLog.Error("faq api: locale", "error", err)
writeError(w, http.StatusInternalServerError, "Internal server error")
return
}
@@ -73,7 +72,7 @@ func Show(app *backpack.App) http.HandlerFunc {
var rows []models.FAQ
if err := db.Where("slug = ? AND locale_id = ? AND is_active = ?", slug, locale.ID, true).
Order("id ASC").Limit(1).Find(&rows).Error; err != nil {
slog.Default().Error("faq api: load faq", "slug", slug, "error", err)
pluginLog.Error("faq api: load faq", "slug", slug, "error", err)
writeError(w, http.StatusInternalServerError, "Internal server error")
return
}

View File

@@ -0,0 +1,7 @@
package api
import "git.golem15.com/golem15/summercms/modules/diary"
// pluginLog is the plugin's logger: its records carry component=faq, so
// config/log.yaml can raise or lower them (log.components.faq).
var pluginLog = diary.For("faq")