/
config_cmd.go
52 lines (44 loc) · 1.19 KB
/
config_cmd.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
44
45
46
47
48
49
50
51
52
package generate
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/gobuffalo/genny/v2"
"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/pop/v6/genny/config"
"github.com/gobuffalo/pop/v6/internal/defaults"
"github.com/spf13/cobra"
)
func init() {
ConfigCmd.Flags().StringVarP(&dialect, "type", "t", "postgres", fmt.Sprintf("The type of database you want to use (%s)", strings.Join(pop.AvailableDialects, ", ")))
}
var dialect string
// ConfigCmd is the command to generate pop config files
var ConfigCmd = &cobra.Command{
Use: "config",
Short: "Generates a database.yml file for your project.",
PersistentPreRun: func(c *cobra.Command, args []string) {},
RunE: func(cmd *cobra.Command, args []string) error {
cflag := cmd.Flag("config")
cflagVal := ""
if cflag != nil {
cflagVal = cflag.Value.String()
}
cfgFile := defaults.String(cflagVal, "database.yml")
run := genny.WetRunner(context.Background())
pwd, _ := os.Getwd()
g, err := config.New(&config.Options{
Root: pwd,
Prefix: filepath.Base(pwd),
FileName: cfgFile,
Dialect: dialect,
})
if err != nil {
return err
}
run.With(g)
return run.Run()
},
}