github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/plugins/tools/db/drop.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 DropCommand struct { 11 connectionName string 12 13 flags *pflag.FlagSet 14 } 15 16 func (d DropCommand) Name() string { 17 return "drop" 18 } 19 20 func (d DropCommand) HelpText() string { 21 return "drops database in GO_ENV or --conn flag" 22 } 23 24 func (d DropCommand) ParentName() string { 25 return "database" 26 } 27 28 func (d *DropCommand) Run(ctx context.Context, root string, args []string) error { 29 conn := pop.Connections[d.connectionName] 30 if conn == nil { 31 return ErrConnectionNotFound 32 } 33 34 return conn.Dialect.DropDB() 35 } 36 37 func (d *DropCommand) ParseFlags(args []string) { 38 d.flags = pflag.NewFlagSet(d.Name(), pflag.ContinueOnError) 39 d.flags.Usage = func() {} 40 d.flags.StringVarP(&d.connectionName, "conn", "", "development", "the name of the connection to use") 41 d.flags.Parse(args) //nolint:errcheck,we don't care hence the flag 42 } 43 44 func (d *DropCommand) Flags() *pflag.FlagSet { 45 return d.flags 46 }