github.com/wawandco/oxplugins@v0.7.11/tools/db/drop.go (about)

     1  package db
     2  
     3  import (
     4  	"context"
     5  
     6  	pop4 "github.com/gobuffalo/pop"
     7  	pop5 "github.com/gobuffalo/pop/v5"
     8  	"github.com/spf13/pflag"
     9  )
    10  
    11  type DropCommand struct {
    12  	connections    map[string]URLProvider
    13  	connectionName string
    14  
    15  	flags *pflag.FlagSet
    16  }
    17  
    18  func (d DropCommand) Name() string {
    19  	return "drop"
    20  }
    21  
    22  func (d DropCommand) HelpText() string {
    23  	return "drops database in GO_ENV or --conn flag"
    24  }
    25  
    26  func (d DropCommand) ParentName() string {
    27  	return "db"
    28  }
    29  
    30  func (d *DropCommand) Run(ctx context.Context, root string, args []string) error {
    31  	conn := d.connections[d.connectionName]
    32  	if conn == nil {
    33  		return ErrConnectionNotFound
    34  	}
    35  
    36  	if c, ok := conn.(*pop4.Connection); ok {
    37  		return c.Dialect.DropDB()
    38  	}
    39  
    40  	if c, ok := conn.(*pop5.Connection); ok {
    41  		return c.Dialect.DropDB()
    42  	}
    43  
    44  	return nil
    45  }
    46  
    47  func (d *DropCommand) ParseFlags(args []string) {
    48  	d.flags = pflag.NewFlagSet(d.Name(), pflag.ContinueOnError)
    49  	d.flags.StringVarP(&d.connectionName, "conn", "", "development", "the name of the connection to use")
    50  	d.flags.Parse(args) //nolint:errcheck,we don't care hence the flag
    51  }
    52  
    53  func (d *DropCommand) Flags() *pflag.FlagSet {
    54  	return d.flags
    55  }