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:
@@ -29,6 +29,17 @@ func Import(app *backpack.App) bonfire.Command {
|
||||
return bonfire.Command{
|
||||
Name: "sitemap:import",
|
||||
Description: "Import sitemap URLs from a JSON manifest file",
|
||||
Long: `Reads a JSON array of URL entries ({"url": "/path", "changefreq":
|
||||
"monthly", "priority": "0.5"}; changefreq and priority are optional) and puts
|
||||
them into the sitemap definition that /sitemap.xml serves, in one
|
||||
transaction. Every entry needs a url that is a path or an http(s) URL; one
|
||||
bad entry stops the import before anything is written.
|
||||
|
||||
By default the import replaces the definition's url items and keeps its
|
||||
dynamic items (pages, posts and other generated types). --append adds the
|
||||
URLs and keeps every existing item. --theme is accepted for the PHP command's
|
||||
sake: only the default definition is served, so the URLs always go there.
|
||||
It ends with "Imported N URLs into sitemap definition for theme 'default'."`,
|
||||
Args: []bonfire.Arg{
|
||||
{Name: "file", Description: "Path to the JSON manifest (relative to the working directory or absolute)", Required: true},
|
||||
},
|
||||
@@ -36,6 +47,10 @@ func Import(app *backpack.App) bonfire.Command {
|
||||
{Name: "theme", Description: "Theme code of the PHP plugin; /sitemap.xml serves only the default definition"},
|
||||
{Name: "append", Description: "Add URLs without removing existing url-type items", Bare: true},
|
||||
},
|
||||
Examples: []bonfire.Example{
|
||||
{Command: "sitemap:import urls.json", Description: "Replace the url items with the manifest's URLs"},
|
||||
{Command: "sitemap:import urls.json --append", Description: "Add the URLs and keep every existing item"},
|
||||
},
|
||||
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
||||
file, _ := in.Argument("file")
|
||||
db, done, err := lookupDB(ctx, app)
|
||||
@@ -100,7 +115,7 @@ func ImportFile(ctx context.Context, db *gorm.DB, file, theme string, appendMode
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out.Info(fmt.Sprintf("Imported %d URLs into sitemap definition for theme '%s'.", len(newItems), models.DefinitionTheme))
|
||||
out.Success(fmt.Sprintf("Imported %d URLs into sitemap definition for theme '%s'.", len(newItems), models.DefinitionTheme))
|
||||
if kept > 0 {
|
||||
label := "existing non-URL (dynamic)"
|
||||
if appendMode {
|
||||
|
||||
Reference in New Issue
Block a user