diff options
author | r <r@freesoftwareextremist.com> | 2022-01-02 10:52:15 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2022-01-02 10:55:26 +0000 |
commit | 003233d60da4a2b69260642e57757bba48021ca1 (patch) | |
tree | 2d429cdfb05c4473523538aef692f268020b0d40 /config | |
parent | 21ef7a66106958bd61534e5d0603b447e6fe306d (diff) | |
download | bloat-003233d60da4a2b69260642e57757bba48021ca1.tar.gz bloat-003233d60da4a2b69260642e57757bba48021ca1.zip |
Change config file lookup
- Look for both local and global config file
- Directly generate the global config file with make install
Diffstat (limited to 'config')
-rw-r--r-- | config/config.go | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/config/config.go b/config/config.go index 8678f52..bbb327c 100644 --- a/config/config.go +++ b/config/config.go @@ -108,21 +108,30 @@ func Parse(r io.Reader) (c *config, err error) { return } -func ParseFile(file string) (c *config, err error) { - f, err := os.Open(file) - if err != nil { - return - } - defer f.Close() - - info, err := f.Stat() - if err != nil { - return +func ParseFiles(files []string) (c *config, err error) { + var lastErr error + for _, file := range files { + f, err := os.Open(file) + if err != nil { + lastErr = err + if os.IsNotExist(err) { + continue + } + return nil, err + } + defer f.Close() + info, err := f.Stat() + if err != nil { + lastErr = err + return nil, err + } + if info.IsDir() { + continue + } + return Parse(f) } - - if info.IsDir() { - return nil, errors.New("invalid config file") + if lastErr == nil { + lastErr = errors.New("invalid config file") } - - return Parse(f) + return nil, lastErr } |