Skip to content

Commit

Permalink
make config truly optional
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed May 5, 2021
1 parent 5687d4e commit 0eaca4e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ func loadConfiguration(filename string, moduleRoot string) (*Config, error) {
return nil, errors.New("no -config specified and could not automatically find go module root")
}

// try if there is a .gimps.yaml in the module root
filename = filepath.Join(moduleRoot, defaultConfigFile)

if _, err := os.Stat(filename); err != nil {
// file does not exist, so we just return the default config
return defaultConfig(&Config{}), nil
}

// file exists, continue loading as normal
}

f, err := os.Open(filename)
Expand All @@ -60,7 +68,11 @@ func loadConfiguration(filename string, moduleRoot string) (*Config, error) {
return nil, err
}

if c.Exclude == nil || len(c.Exclude) == 0 {
return defaultConfig(c), nil
}

func defaultConfig(c *Config) *Config {
if c.Exclude == nil {
c.Exclude = defaultExcludes
}

Expand All @@ -69,5 +81,5 @@ func loadConfiguration(filename string, moduleRoot string) (*Config, error) {
c.DetectGeneratedFiles = &yesPlease
}

return c, nil
return c
}

0 comments on commit 0eaca4e

Please sign in to comment.