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:39:11 +02:00
parent f7eddd5572
commit 86564746de
9 changed files with 169 additions and 6 deletions

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=menu, so
// config/log.yaml can raise or lower them (log.components.menu).
var pluginLog = diary.For("menu")

View File

@@ -3,7 +3,6 @@ package api
import (
"errors"
"log/slog"
"net/http"
"regexp"
@@ -48,7 +47,7 @@ func Show(app *backpack.App) http.HandlerFunc {
db = db.WithContext(r.Context())
var menus []models.Menu
if err := db.Where("code = ? AND is_active = ?", code, true).Order("id ASC").Limit(1).Find(&menus).Error; err != nil {
slog.Default().Error("menu api: load menu", "code", code, "error", err)
pluginLog.Error("menu api: load menu", "code", code, "error", err)
writeError(w, http.StatusInternalServerError, "Internal server error")
return
}
@@ -60,7 +59,7 @@ func Show(app *backpack.App) http.HandlerFunc {
var entries []models.MenuEntry
if err := db.Where("menu_id = ? AND is_published = ?", menu.ID, true).
Order("sort_order ASC NULLS LAST, id ASC").Find(&entries).Error; err != nil {
slog.Default().Error("menu api: load entries", "code", code, "error", err)
pluginLog.Error("menu api: load entries", "code", code, "error", err)
writeError(w, http.StatusInternalServerError, "Internal server error")
return
}