Skip to content

Commit 44f8603

Browse files
Merge pull request #9 from shipyard/use-env-var-prefix
Use a special prefix for env vars and add a dash replacer for flags
2 parents dd88de8 + 6860ce6 commit 44f8603

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

cmd/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"path/filepath"
9+
"strings"
910

1011
"github.com/fatih/color"
1112
"github.com/spf13/cobra"
@@ -46,6 +47,10 @@ func Execute() {
4647
}
4748

4849
func init() {
50+
replacer := strings.NewReplacer("-", "_")
51+
viper.SetEnvKeyReplacer(replacer)
52+
viper.SetEnvPrefix("shipyard")
53+
viper.AutomaticEnv()
4954
cobra.OnInitialize(initConfig)
5055

5156
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.shipyard/config.yaml)")
@@ -79,8 +84,6 @@ func setupCommands() {
7984
}
8085

8186
func initConfig() {
82-
viper.AutomaticEnv()
83-
8487
if cfgFile != "" {
8588
viper.SetConfigFile(cfgFile)
8689
if err := viper.ReadInConfig(); err != nil {

0 commit comments

Comments
 (0)