github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/add/options.go (about) 1 package add 2 3 import ( 4 "os" 5 6 "github.com/gobuffalo/buffalo/plugins/plugdeps" 7 "github.com/gobuffalo/meta" 8 "github.com/segakazzz/buffalo/internal/takeon/github.com/markbates/errx" 9 ) 10 11 // Options container for passing needed info for 12 // adding plugins to the config file. 13 type Options struct { 14 App meta.App 15 Plugins []plugdeps.Plugin 16 } 17 18 // Validate that options are usuable 19 func (opts *Options) Validate() error { 20 if opts.App.IsZero() { 21 pwd, err := os.Getwd() 22 if err != nil { 23 return err 24 } 25 opts.App = meta.New(pwd) 26 } 27 if len(opts.Plugins) == 0 { 28 plugs, err := plugdeps.List(opts.App) 29 if err != nil && (errx.Unwrap(err) != plugdeps.ErrMissingConfig) { 30 return err 31 } 32 opts.Plugins = plugs.List() 33 } 34 35 for i, p := range opts.Plugins { 36 p.Tags = opts.App.BuildTags("", p.Tags...) 37 opts.Plugins[i] = p 38 } 39 return nil 40 }