- setup: introduction, installation rewritten from install to serve, configuration with the keys an application sets - console: introduction, setup and maintenance, scaffolding, writing commands, utilities; every command name is checker-verified - bonfire ExampleCatalog shows arguments, bare and repeatable flags - index links the section introductions; TestDocsRequiredPages lists the seven new pages
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package bonfire_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/bonfire"
|
|
)
|
|
|
|
func ExampleCall() {
|
|
commands := []bonfire.Command{{
|
|
Name: "acme:greet",
|
|
Description: "Greet someone by name",
|
|
Args: []bonfire.Arg{{Name: "name", Required: true}},
|
|
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
|
name, _ := in.Argument("name")
|
|
out.Printf("Hello, %s\n", name)
|
|
return nil
|
|
},
|
|
}}
|
|
|
|
if err := bonfire.Call(context.Background(), commands, "acme:greet", []string{"blog"}, os.Stdout); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
// Output: Hello, blog
|
|
}
|
|
|
|
func ExampleCatalog() {
|
|
publish := bonfire.Command{
|
|
Name: "blog:publish",
|
|
Description: "Publish a post",
|
|
Args: []bonfire.Arg{{Name: "slug", Description: "Post slug", Required: true}},
|
|
Flags: []bonfire.Flag{
|
|
{Name: "dry-run", Description: "Report without writing", Bare: true},
|
|
{Name: "tag", Description: "Tag to add (repeatable)", Repeatable: true},
|
|
},
|
|
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
|
slug, _ := in.Argument("slug")
|
|
dryRun, _ := in.Flag("dry-run")
|
|
out.Printf("publish %s, tags %v, dry run %s\n", slug, in.Flags("tag"), dryRun)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// The generated main publishes a catalog of every command on the app.
|
|
catalog := bonfire.NewCatalog([]bonfire.Command{publish})
|
|
args := []string{"hello-world", "--tag", "news", "--tag", "go", "--dry-run"}
|
|
if err := catalog.Call(context.Background(), "blog:publish", args, os.Stdout); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
// Output: publish hello-world, tags [news go], dry run true
|
|
}
|