Skip to content

Commit 772a775

Browse files
authored
Merge pull request #666 from yoRyuuuuu/feature/yaml-config-support
Add support for '.yaml' extension to default configuration
2 parents 692c4f5 + 3c7be92 commit 772a775

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

Diff for: config/config.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
const DefaultDocPath = "dbdoc"
2222

23-
var DefaultConfigFilePaths = []string{".tbls.yml", "tbls.yml"}
23+
var DefaultConfigFilePaths = []string{".tbls.yml", "tbls.yml", ".tbls.yaml", "tbls.yaml"}
2424

2525
// DefaultERFormat is the default ER diagram format
2626
const DefaultERFormat = "svg"
@@ -361,15 +361,21 @@ func (c *Config) LoadConfigFile(path string) (err error) {
361361
err = errors.WithStack(err)
362362
}()
363363
if path == "" && os.Getenv("TBLS_DSN") == "" {
364+
var paths []string
364365
for _, p := range DefaultConfigFilePaths {
365366
if f, err := os.Stat(filepath.Join(c.root, p)); err == nil && !f.IsDir() {
366-
if path != "" {
367-
return fmt.Errorf("duplicate config file [%s, %s]", path, p)
368-
}
369-
path = p
367+
paths = append(paths, p)
370368
}
371369
}
370+
if len(paths) == 0 {
371+
return nil
372+
} else if len(paths) > 1 {
373+
return fmt.Errorf("duplicate config file [%s]", strings.Join(paths, ", "))
374+
} else {
375+
path = paths[0]
376+
}
372377
}
378+
373379
if path == "" {
374380
return nil
375381
}

Diff for: config/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestDuplicateConfigFile(t *testing.T) {
6969
root: filepath.Join(testdataDir(), "config"),
7070
}
7171
got := config.LoadConfigFile("")
72-
want := "duplicate config file [.tbls.yml, tbls.yml]"
72+
want := "duplicate config file [.tbls.yml, tbls.yml, .tbls.yaml, tbls.yaml]"
7373
if fmt.Sprintf("%v", got) != want {
7474
t.Errorf("got %v\nwant %v", got, want)
7575
}

Diff for: testdata/config/.tbls.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

Diff for: testdata/config/tbls.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

0 commit comments

Comments
 (0)