Skip to content

Commit

Permalink
fix: read config flag correctly (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored Oct 3, 2022
1 parent 85989f4 commit 7500dd4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
)

var (
cfgFile string
cfgFile *string
rootCmd = &cobra.Command{
Use: name,
Aliases: []string{},
Expand All @@ -35,17 +35,17 @@ func Execute() error {
func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().String(configFlag, "", "use this configuration file")
cfgFile = rootCmd.PersistentFlags().StringP(configFlag, "c", "", "use this configuration file")
addBoolFlag(rootCmd.PersistentFlags(), debugFlag, false, "enable debug messages")
}

func initConfig() {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

if cfgFile != "" {
if *cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
viper.SetConfigFile(*cfgFile)
} else {
// Find home directory.
viper.SetConfigName(name)
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
Expand Down

0 comments on commit 7500dd4

Please sign in to comment.