aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2022-01-02 10:52:15 +0000
committerr <r@freesoftwareextremist.com>2022-01-02 10:55:26 +0000
commit003233d60da4a2b69260642e57757bba48021ca1 (patch)
tree2d429cdfb05c4473523538aef692f268020b0d40 /config
parent21ef7a66106958bd61534e5d0603b447e6fe306d (diff)
downloadbloat-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.go39
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
}