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:
@@ -19,7 +19,18 @@ import (
|
||||
func BackfillHandles(app *backpack.App) bonfire.Command {
|
||||
return bonfire.Command{
|
||||
Name: "user:backfill-handles",
|
||||
Description: "Assign unique handles to users that do not have one (D-15)",
|
||||
Description: "Assign unique handles to users that do not have one",
|
||||
Long: `Gives every user without a handle a unique one, derived the same way as
|
||||
for a new registration, with a progress bar over the users (hidden under
|
||||
-q). Users that already have a handle are not touched, so running it again
|
||||
changes nothing.
|
||||
|
||||
Run it once after copying users from WinterCMS, which had no handles. It
|
||||
ends with "Assigned handles to N user(s)".`,
|
||||
Examples: []bonfire.Example{
|
||||
{Command: "user:backfill-handles", Description: "Assign a handle to every user that has none"},
|
||||
{Command: "user:backfill-handles -q", Description: "Run it quietly, printing only the result line"},
|
||||
},
|
||||
Run: func(ctx context.Context, _ bonfire.Input, out bonfire.Output) error {
|
||||
if app == nil {
|
||||
return fmt.Errorf("user:backfill-handles: app is nil")
|
||||
@@ -38,11 +49,20 @@ func BackfillHandles(app *backpack.App) bonfire.Command {
|
||||
return err
|
||||
}
|
||||
n := 0
|
||||
for i := range users {
|
||||
if err := classes.AssignHandle(ctx, gdb, &users[i]); err != nil {
|
||||
if len(users) > 0 {
|
||||
err := out.Progress(len(users), func(p bonfire.Progress) error {
|
||||
for i := range users {
|
||||
if err := classes.AssignHandle(ctx, gdb, &users[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
n++
|
||||
p.Advance(1)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n++
|
||||
}
|
||||
out.Success(fmt.Sprintf("Assigned handles to %d user(s)", n))
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user