forked from gobuffalo/pop
/
config_cmd.go
85 lines (71 loc) · 2.1 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package generate
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/pop"
"github.com/gobuffalo/pop/genny/config"
"github.com/gobuffalo/pop/internal/defaults"
"github.com/gobuffalo/pop/internal/oncer"
"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()
},
}
// GenerateConfig generates pop configuration files.
//
// Deprecated: use github.com/gobuffalo/pop/genny/config instead.
func GenerateConfig(cfgFile string, data map[string]interface{}) error {
oncer.Deprecate(0, "generate.GenerateConfig", "Use github.com/gobuffalo/pop/genny/config instead.")
return Config(cfgFile, data)
}
// Config generates pop configuration files.
// Deprecated: use github.com/gobuffalo/pop/genny/config instead.
func Config(cfgFile string, data map[string]interface{}) error {
oncer.Deprecate(0, "generate.Config", "Use github.com/gobuffalo/pop/genny/config instead.")
pwd, _ := os.Getwd()
run := genny.WetRunner(context.Background())
d, _ := data["dialect"].(string)
g, err := config.New(&config.Options{
Root: pwd,
Prefix: filepath.Base(pwd),
FileName: cfgFile,
Dialect: d,
})
if err != nil {
return err
}
run.With(g)
return run.Run()
}