Skip to content

Commit

Permalink
cmd: observe env for debug and bind the flag to it
Browse files Browse the repository at this point in the history
  • Loading branch information
snosratiershad committed Jun 15, 2024
1 parent 01b50e0 commit 7c9508e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions flagd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func init() {
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().BoolVarP(&Debug, "debug", "x", false, "verbose logging")
// Bind the cobra flag to viper key
if err := viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")); err != nil {
fmt.Fprintln(os.Stderr, "error when binding flags", err.Error())
}
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.agent.yaml)")
rootCmd.AddCommand(startCmd)
rootCmd.AddCommand(versionCmd)
Expand All @@ -69,6 +73,7 @@ func initConfig() {
}

viper.AutomaticEnv() // read in environment variables that match
Debug = viper.GetBool("debug")

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
Expand Down

0 comments on commit 7c9508e

Please sign in to comment.