@@ -20,10 +20,10 @@ import (
2020 "github.com/corneliusweig/ketall/pkg/options"
2121 "github.com/sirupsen/logrus"
2222 "io"
23+ "k8s.io/client-go/util/homedir"
2324 "path/filepath"
2425
2526 "github.com/corneliusweig/ketall/pkg"
26- "github.com/mitchellh/go-homedir"
2727 "github.com/pkg/errors"
2828 "github.com/spf13/cobra"
2929 "github.com/spf13/viper"
@@ -83,6 +83,11 @@ func init() {
8383 ketallOptions .GenericCliFlags .AddFlags (rootCmd .Flags ())
8484 ketallOptions .PrintFlags .AddFlags (rootCmd )
8585
86+ err := viper .BindPFlags (rootCmd .Flags ())
87+ if err != nil {
88+ logrus .Errorf ("Cannot bind flags: %s" , err )
89+ }
90+
8691 rootCmd .PersistentPreRunE = func (cmd * cobra.Command , args []string ) error {
8792 if err := SetUpLogs (ketallOptions .Streams .ErrOut , v ); err != nil {
8893 return err
@@ -94,22 +99,17 @@ func init() {
9499// initConfig reads in config file and ENV variables if set.
95100func initConfig () {
96101 if ketallOptions .CfgFile != "" {
97- // Use config file from the flag.
98102 viper .SetConfigFile (ketallOptions .CfgFile )
99103 } else {
100- // Find home directory.
101- home , err := homedir .Dir ()
102- if err != nil {
103- logrus .Warnf ("Could not read home dir: %s" , err )
104- return
105- }
106-
107- // Search config in "~/.kube/ketall" (without extension).
108- viper .AddConfigPath (filepath .Join (home , ".kube" ))
104+ // Search for "ketall.yaml" in "." and "~/.kube/"
105+ viper .AddConfigPath ("." )
106+ viper .AddConfigPath (filepath .Join (homedir .HomeDir (), ".kube" ))
109107 viper .SetConfigName ("ketall" )
110108 }
111109
112- viper .AutomaticEnv () // read in environment variables that match
110+ // read in environment variables that match
111+ viper .SetEnvPrefix ("ketall" )
112+ viper .AutomaticEnv ()
113113
114114 // If a config file is found, read it in.
115115 if err := viper .ReadInConfig (); err == nil {
0 commit comments