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.

user:token:create and user:token:list gain --json, user:backfill-handles a
progress bar; planning IDs leave the descriptions.
This commit is contained in:
Jakub Zych
2026-10-21 18:03:50 +02:00
parent 35cf16689d
commit 9986342c23
17 changed files with 342 additions and 39 deletions

View File

@@ -3,7 +3,6 @@ package classes
import (
"context"
"fmt"
"log/slog"
"strconv"
"time"
@@ -241,7 +240,7 @@ func ForceDeleteCleanup(ctx context.Context, db *gorm.DB, bucket *blob.Bucket, u
// The rows are gone by now, so a blob that cannot be removed is
// orphaned, not lost data: log it and carry on.
if err := attach.DeleteKeys(ctx, bucket, keys); err != nil {
slog.Default().Warn("golem15.user: remove attachment blobs of a deleted user", "user_id", userID, "err", err)
pluginLog.Warn("golem15.user: remove attachment blobs of a deleted user", "user_id", userID, "err", err)
}
})
return nil

View File

@@ -2,7 +2,6 @@ package classes
import (
"context"
"log/slog"
"strings"
"git.golem15.com/golem15/summercms/modules/backpack"
@@ -36,7 +35,7 @@ func AuthorizeUser() lighthouse.AuthorizerFunc {
func RegisterUserAuthorizer(app *backpack.App) error {
svc, err := lighthouse.From(app)
if err != nil {
slog.Default().Warn("golem15.user: lighthouse unavailable; user authorizer not registered", "err", err)
pluginLog.Warn("golem15.user: lighthouse unavailable; user authorizer not registered", "err", err)
return nil
}
if svc == nil || svc.Registry() == nil {

View File

@@ -5,7 +5,6 @@ import (
"crypto/md5"
"errors"
"fmt"
"log/slog"
"strconv"
"strings"
@@ -52,7 +51,7 @@ func AvatarURL(ctx context.Context, app *backpack.App, user *models.User, size i
}
url, err := f.Thumb(ctx, bucket, size, size, "auto")
if err != nil {
slog.Default().Error("golem15.user: avatar thumb", "err", err)
pluginLog.Error("golem15.user: avatar thumb", "err", err)
return "/" + attach.BlobKey(f.DiskName), nil
}
return url, nil

7
classes/logger.go Normal file
View File

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

View File

@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"net/http"
"strconv"
"strings"
@@ -99,7 +98,7 @@ func EndRequestSession(ctx context.Context, app *backpack.App, w http.ResponseWr
if app != nil && app.Config != nil {
loaded, err := bouncer.LoadCookieConfig(app.Config)
if err != nil {
slog.Default().Warn("golem15.user: end session: cookie config", "err", err)
pluginLog.Warn("golem15.user: end session: cookie config", "err", err)
} else {
cfg = loaded
}
@@ -126,7 +125,7 @@ func revokeSessionToken(ctx context.Context, app *backpack.App, raw string) {
return
}
if err := bl.Add(ctx, jti, exp, time.Now()); err != nil {
slog.Default().Warn("golem15.user: end session: blacklist token", "err", err)
pluginLog.Warn("golem15.user: end session: blacklist token", "err", err)
}
}