Skip to content

Commit 3edce90

Browse files
committed
version command now works without configuration
1 parent 27c1213 commit 3edce90

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

cmd/generate.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/keenmate/db-gen/common"
66
dbGen "github.com/keenmate/db-gen/src"
77
"github.com/spf13/cobra"
8+
"github.com/spf13/viper"
89
"log"
910
)
1011

@@ -13,7 +14,16 @@ var generateCmd = &cobra.Command{
1314
Short: "Generate code",
1415
Long: "Generate code for calling database stored procedures",
1516
Run: func(cmd *cobra.Command, args []string) {
16-
err := doGenerate()
17+
configLocation := viper.GetString("config")
18+
19+
_, err := dbGen.ReadConfig(configLocation)
20+
if err != nil {
21+
dbGen.Exit("configuration error: %s", err)
22+
}
23+
24+
viper.AutomaticEnv() // read in environment variables that match
25+
26+
err = doGenerate()
1727
if err != nil {
1828
dbGen.Exit(err.Error())
1929
}

cmd/root.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
dbGen "github.com/keenmate/db-gen/src"
55
"github.com/spf13/cobra"
6-
"github.com/spf13/viper"
76
"os"
87
)
98

@@ -45,12 +44,5 @@ func init() {
4544

4645
// initConfig reads in config file and ENV variables if set.
4746
func initConfig() {
48-
configLocation := viper.GetString("config")
4947

50-
_, err := dbGen.ReadConfig(configLocation)
51-
if err != nil {
52-
dbGen.Exit("configuration error: %s", err)
53-
}
54-
55-
viper.AutomaticEnv() // read in environment variables that match
5648
}

0 commit comments

Comments
 (0)