github.com/JarrahG/buffalocli@v0.0.0-20230801092127-b85bfd5d395a/internal/genny/add/options.go (about) 1 package add 2 3 import ( 4 "errors" 5 "os" 6 7 "github.com/JarrahG/buffalocli/internal/plugins/plugdeps" 8 "github.com/gobuffalo/meta" 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 && !errors.Is(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 }