package main import ( "context" "fmt" "os" "git.golem15.com/golem15/summercms/bonfire" "git.golem15.com/golem15/summercms/internal/build" "git.golem15.com/golem15/summercms/internal/dev" ) func main() { root, err := bonfire.NewRoot("summer", toolCommands(), os.Stdout) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } root.SetArgs(os.Args[1:]) if err := root.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func toolCommands() []bonfire.Command { return []bonfire.Command{ buildCommand(), makePluginCommand(), addPluginCommand(), devCommand(), } } func buildCommand() bonfire.Command { return bonfire.Command{ Name: "build", Description: "Generate plugin imports and build the app binary", Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error { dir, err := os.Getwd() if err != nil { return err } return build.App(ctx, dir, out) }, } } func makePluginCommand() bonfire.Command { return bonfire.Command{ Name: "make:plugin", Description: "Scaffold a compiling plugin module from a vendor.plugin id", Args: []bonfire.Arg{{ Name: "id", Description: "Plugin ID in vendor.plugin form", Required: true, }}, Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error { id, ok := in.Argument("id") if !ok || id == "" { return fmt.Errorf("make:plugin requires a vendor.plugin id") } dir, err := os.Getwd() if err != nil { return err } created, err := build.MakePlugin(ctx, dir, id) if err != nil { return err } out.Printf("created %s\n", created) return nil }, } } func devCommand() bonfire.Command { return bonfire.Command{ Name: "dev", Description: "Watch sources and rebuild the app binary", Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error { dir, err := os.Getwd() if err != nil { return err } return dev.Watch(ctx, dir, out) }, } } func addPluginCommand() bonfire.Command { return bonfire.Command{ Name: "plugin:add", Description: "Register a local plugin module in the app manifest and workspace", Args: []bonfire.Arg{{ Name: "dir", Description: "Local plugin directory", Required: true, }}, Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error { pluginDir, ok := in.Argument("dir") if !ok || pluginDir == "" { return fmt.Errorf("plugin:add requires a local plugin directory") } dir, err := os.Getwd() if err != nil { return err } if err := build.AddPlugin(ctx, dir, pluginDir); err != nil { return err } out.Printf("added %s\n", pluginDir) return nil }, } }