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:
@@ -39,12 +39,28 @@ type ImportStats struct {
|
||||
func ImportPosts(app *backpack.App) bonfire.Command {
|
||||
return bonfire.Command{
|
||||
Name: "journal:import-posts",
|
||||
Description: "Import journal posts with translations from JSON files.",
|
||||
Description: "Import journal posts with their translations from JSON files",
|
||||
Long: `Reads every *.json file of the import directory (the files
|
||||
journal:export-posts writes) and creates a post for each slug that does not
|
||||
exist yet, with its translations and categories (missing categories are
|
||||
created). A post whose slug already exists is skipped unless --force is
|
||||
given, which updates it from the file. Titles lose the draft lock mark.
|
||||
|
||||
The whole import runs in one transaction; each post prints one line
|
||||
(created, updated or skipped) and a file that is not valid JSON or has no
|
||||
slug is reported and counted as failed. --dry-run walks the files without
|
||||
writing anything. It ends with "Results: N created, N updated, N skipped, N
|
||||
failed".`,
|
||||
Flags: []bonfire.Flag{
|
||||
{Name: "path", Description: "Import directory (default: journal-export)"},
|
||||
{Name: "force", Description: "Update existing posts (default: skip existing)", Bare: true},
|
||||
{Name: "dry-run", Description: "Show what would be imported without making changes", Bare: true},
|
||||
},
|
||||
Examples: []bonfire.Example{
|
||||
{Command: "journal:import-posts --dry-run", Description: "Show what journal-export/ would create or skip"},
|
||||
{Command: "journal:import-posts --path backups/journal", Description: "Create the posts that do not exist yet"},
|
||||
{Command: "journal:import-posts --force", Description: "Also update the posts that already exist"},
|
||||
},
|
||||
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
||||
path := flagOrDefault(in, "path", defaultExportPath)
|
||||
force := flagOn(in, "force")
|
||||
@@ -56,7 +72,7 @@ func ImportPosts(app *backpack.App) bonfire.Command {
|
||||
if dry {
|
||||
out.Info("Dry run complete (no changes made).")
|
||||
}
|
||||
out.Info(fmt.Sprintf("Results: %d created, %d updated, %d skipped, %d failed",
|
||||
out.Success(fmt.Sprintf("Results: %d created, %d updated, %d skipped, %d failed",
|
||||
stats.Created, stats.Updated, stats.Skipped, stats.Failed))
|
||||
return nil
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user