Recognize tfvars files as hcl by default.

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Jim Razmus II 2020-05-13 12:15:28 -05:00 committed by Márk Sági-Kazár
parent 65f16c1738
commit b1fdc47b0d

View file

@ -105,6 +105,9 @@ func init() {
encoderRegistry.RegisterEncoder("hcl", codec) encoderRegistry.RegisterEncoder("hcl", codec)
decoderRegistry.RegisterDecoder("hcl", codec) decoderRegistry.RegisterDecoder("hcl", codec)
encoderRegistry.RegisterEncoder("tfvars", codec)
decoderRegistry.RegisterDecoder("tfvars", codec)
} }
} }
@ -329,7 +332,7 @@ func NewWithOptions(opts ...Option) *Viper {
// can use it in their testing as well. // can use it in their testing as well.
func Reset() { func Reset() {
v = New() v = New()
SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env", "ini"} SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"}
SupportedRemoteProviders = []string{"etcd", "consul", "firestore"} SupportedRemoteProviders = []string{"etcd", "consul", "firestore"}
} }
@ -368,7 +371,7 @@ type RemoteProvider interface {
} }
// SupportedExts are universally supported extensions. // SupportedExts are universally supported extensions.
var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "dotenv", "env", "ini"} var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"}
// SupportedRemoteProviders are universally supported remote providers. // SupportedRemoteProviders are universally supported remote providers.
var SupportedRemoteProviders = []string{"etcd", "consul", "firestore"} var SupportedRemoteProviders = []string{"etcd", "consul", "firestore"}
@ -1624,7 +1627,7 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
buf.ReadFrom(in) buf.ReadFrom(in)
switch format := strings.ToLower(v.getConfigType()); format { switch format := strings.ToLower(v.getConfigType()); format {
case "yaml", "yml", "json", "toml", "hcl": case "yaml", "yml", "json", "toml", "hcl", "tfvars":
err := decoderRegistry.Decode(format, buf.Bytes(), &c) err := decoderRegistry.Decode(format, buf.Bytes(), &c)
if err != nil { if err != nil {
return ConfigParseError{err} return ConfigParseError{err}
@ -1681,7 +1684,7 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
func (v *Viper) marshalWriter(f afero.File, configType string) error { func (v *Viper) marshalWriter(f afero.File, configType string) error {
c := v.AllSettings() c := v.AllSettings()
switch configType { switch configType {
case "yaml", "yml", "json", "toml", "hcl": case "yaml", "yml", "json", "toml", "hcl", "tfvars":
b, err := encoderRegistry.Encode(configType, c) b, err := encoderRegistry.Encode(configType, c)
if err != nil { if err != nil {
return ConfigMarshalError{err} return ConfigMarshalError{err}