Skip to content

Commit 22103f8

Browse files
authored
Merge pull request #68 from netlify/support-yaml-syntax
Support YAML configurations
2 parents 6181adc + 659f37a commit 22103f8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

nconf/configuration.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package nconf
33
import (
44
"os"
55
"strings"
6+
"path/filepath"
67

78
"github.com/pkg/errors"
89
"github.com/spf13/cobra"
@@ -11,8 +12,6 @@ import (
1112

1213
// LoadConfig loads the config from a file if specified, otherwise from the environment
1314
func LoadConfig(cmd *cobra.Command, serviceName string, input interface{}) error {
14-
viper.SetConfigType("json")
15-
1615
if err := viper.BindPFlags(cmd.Flags()); err != nil {
1716
return err
1817
}
@@ -23,6 +22,17 @@ func LoadConfig(cmd *cobra.Command, serviceName string, input interface{}) error
2322

2423
if configFile, _ := cmd.Flags().GetString("config"); configFile != "" {
2524
viper.SetConfigFile(configFile)
25+
26+
if ext := filepath.Ext(configFile); len(ext) > 1 {
27+
switch strings.ToLower(ext[1:]) {
28+
case "yaml", "yml":
29+
viper.SetConfigType("yaml")
30+
case "json":
31+
fallthrough
32+
default:
33+
viper.SetConfigType("json")
34+
}
35+
}
2636
} else {
2737
viper.SetConfigName("config")
2838
viper.AddConfigPath("./")

0 commit comments

Comments
 (0)