Skip to content

Commit

Permalink
Merge pull request #9 from shipyard/use-env-var-prefix
Browse files Browse the repository at this point in the history
Use a special prefix for env vars and add a dash replacer for flags
  • Loading branch information
maxsokolovsky authored Feb 24, 2023
2 parents dd88de8 + 6860ce6 commit 44f8603
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"path/filepath"
"strings"

"github.com/fatih/color"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -46,6 +47,10 @@ func Execute() {
}

func init() {
replacer := strings.NewReplacer("-", "_")
viper.SetEnvKeyReplacer(replacer)
viper.SetEnvPrefix("shipyard")
viper.AutomaticEnv()
cobra.OnInitialize(initConfig)

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

func initConfig() {
viper.AutomaticEnv()

if cfgFile != "" {
viper.SetConfigFile(cfgFile)
if err := viper.ReadInConfig(); err != nil {
Expand Down

0 comments on commit 44f8603

Please sign in to comment.