github.com/dkishere/pop/v6@v6.103.1/soda/cmd/generate/config_cmd.go (about) 1 package generate 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 "path/filepath" 8 "strings" 9 10 "github.com/gobuffalo/genny/v2" 11 "github.com/dkishere/pop/v6" 12 "github.com/dkishere/pop/v6/genny/config" 13 "github.com/dkishere/pop/v6/internal/defaults" 14 "github.com/spf13/cobra" 15 ) 16 17 func init() { 18 ConfigCmd.Flags().StringVarP(&dialect, "type", "t", "postgres", fmt.Sprintf("The type of database you want to use (%s)", strings.Join(pop.AvailableDialects, ", "))) 19 } 20 21 var dialect string 22 23 // ConfigCmd is the command to generate pop config files 24 var ConfigCmd = &cobra.Command{ 25 Use: "config", 26 Short: "Generates a database.yml file for your project.", 27 PersistentPreRun: func(c *cobra.Command, args []string) {}, 28 RunE: func(cmd *cobra.Command, args []string) error { 29 cflag := cmd.Flag("config") 30 cflagVal := "" 31 if cflag != nil { 32 cflagVal = cflag.Value.String() 33 } 34 cfgFile := defaults.String(cflagVal, "database.yml") 35 36 run := genny.WetRunner(context.Background()) 37 38 pwd, _ := os.Getwd() 39 g, err := config.New(&config.Options{ 40 Root: pwd, 41 Prefix: filepath.Base(pwd), 42 FileName: cfgFile, 43 Dialect: dialect, 44 }) 45 if err != nil { 46 return err 47 } 48 run.With(g) 49 50 return run.Run() 51 }, 52 }