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