Use a go-idiomatic constructor for helm.Config [#9]

This commit is contained in:
Erin Call
2019-12-24 09:34:38 -08:00
parent 10e7e7fee5
commit 4ba1e694d9
3 changed files with 29 additions and 28 deletions

View File

@@ -35,23 +35,24 @@ type Config struct {
Force bool `` // Pass --force to applicable helm commands
}
// Populate reads environment variables into the Config, accounting for several possible formats.
func (cfg *Config) Populate() error {
if err := envconfig.Process("plugin", cfg); err != nil {
return err
// NewConfig creates a Config and reads environment variables into it, accounting for several possible formats.
func NewConfig() (*Config, error) {
cfg := Config{}
if err := envconfig.Process("plugin", &cfg); err != nil {
return nil, err
}
prefix := cfg.Prefix
if err := envconfig.Process("", cfg); err != nil {
return err
if err := envconfig.Process("", &cfg); err != nil {
return nil, err
}
if prefix != "" {
if err := envconfig.Process(cfg.Prefix, cfg); err != nil {
return err
if err := envconfig.Process(cfg.Prefix, &cfg); err != nil {
return nil, err
}
}
return nil
return &cfg, nil
}