github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/resource/models.go (about) 1 package resource 2 3 import ( 4 "os/exec" 5 6 "github.com/gobuffalo/flect/name" 7 "github.com/gobuffalo/genny/v2" 8 ) 9 10 func modelCommand(model name.Ident, opts *Options) *exec.Cmd { 11 args := opts.Attrs.Slice() 12 mn := model.Singularize().Underscore().String() 13 args = append([]string{"pop", "g", "model", mn}, args...) 14 15 if opts.SkipMigration { 16 args = append(args, "--skip-migration") 17 } 18 19 return exec.Command("buffalo-pop", args...) 20 } 21 22 func installPop(opts *Options) genny.RunFn { 23 return func(r *genny.Runner) error { 24 if opts.SkipModel { 25 return nil 26 } 27 if _, err := r.LookPath("buffalo-pop"); err != nil { 28 c := exec.Command("go", "get", "github.com/gobuffalo/buffalo-pop/v2") 29 if err := r.Exec(c); err != nil { 30 return err 31 } 32 } 33 return r.Exec(modelCommand(name.New(opts.Model), opts)) 34 } 35 }