github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/db/create.go (about) 1 package db 2 3 import ( 4 "context" 5 6 "github.com/gobuffalo/pop/v6" 7 "github.com/spf13/pflag" 8 ) 9 10 type CreateCommand struct { 11 connectionName string 12 flags *pflag.FlagSet 13 } 14 15 func (d CreateCommand) Name() string { 16 return "create" 17 } 18 19 func (d CreateCommand) HelpText() string { 20 return "creates database in GO_ENV or --conn flag" 21 } 22 23 func (d CreateCommand) ParentName() string { 24 return "database" 25 } 26 27 func (d *CreateCommand) Run(ctx context.Context, root string, args []string) error { 28 conn := pop.Connections[d.connectionName] 29 if conn == nil { 30 return ErrConnectionNotFound 31 } 32 33 return conn.Dialect.CreateDB() 34 } 35 36 func (d *CreateCommand) ParseFlags(args []string) { 37 d.flags = pflag.NewFlagSet(d.Name(), pflag.ContinueOnError) 38 d.flags.Usage = func() {} 39 d.flags.StringVarP(&d.connectionName, "conn", "", "development", "the name of the connection to use") 40 d.flags.Parse(args) //nolint:errcheck,we don't care hence the flag 41 } 42 43 func (d *CreateCommand) Flags() *pflag.FlagSet { 44 return d.flags 45 }