github.com/cheikhshift/buffalo@v0.9.5/buffalo/cmd/generate/action.go (about) 1 package generate 2 3 import ( 4 "errors" 5 "os" 6 7 "github.com/gobuffalo/buffalo/generators/action" 8 "github.com/gobuffalo/makr" 9 "github.com/markbates/inflect" 10 "github.com/spf13/cobra" 11 ) 12 13 //SkipActionTemplate indicates whether we generator should not generate the view layer when generating actions. 14 var SkipActionTemplate = false 15 16 //ActionMethod is the method generated action will be binded to. 17 var ActionMethod = "GET" 18 19 //ActionCmd is the cmd that generates actions. 20 var ActionCmd = &cobra.Command{ 21 Use: "action [name] [actionName...]", 22 Aliases: []string{"a", "actions"}, 23 Short: "Generates new action(s)", 24 RunE: func(cmd *cobra.Command, args []string) error { 25 if len(args) < 2 { 26 return errors.New("you should provide action name and handler name at least") 27 } 28 29 if _, err := os.Stat("actions"); err != nil { 30 return errors.New("actions directory not found, ensure you're inside your buffalo folder") 31 } 32 33 name := args[0] 34 35 data := makr.Data{ 36 "filename": inflect.Underscore(name), 37 "namespace": inflect.Camelize(name), 38 "method": ActionMethod, 39 "skipTemplate": SkipActionTemplate, 40 } 41 42 g, err := action.New(name, args[1:], data) 43 if err != nil { 44 return err 45 } 46 47 return g.Run(".", data) 48 }, 49 }