forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop.go
43 lines (36 loc) · 764 Bytes
/
drop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cmd
import (
"fmt"
"os"
"github.com/gobuffalo/pop"
"github.com/spf13/cobra"
)
var all bool
var dropCmd = &cobra.Command{
Use: "drop",
Short: "Drops databases for you",
Run: func(cmd *cobra.Command, args []string) {
var err error
if len(args) > 0 {
err = fmt.Errorf("no arguments allowed with the drop database command")
fmt.Println(err)
os.Exit(1)
}
if all {
for _, conn := range pop.Connections {
err = pop.DropDB(conn)
if err != nil {
fmt.Println(err)
}
}
} else {
if err := pop.DropDB(getConn()); err != nil {
fmt.Println(err)
}
}
},
}
func init() {
dropCmd.Flags().BoolVarP(&all, "all", "a", false, "Drops all of the databases in the database.yml")
RootCmd.AddCommand(dropCmd)
}