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 }