@@ -11,7 +11,7 @@ import (
11
11
"gopkg.in/yaml.v3"
12
12
)
13
13
14
- const configFilePath = ".mygcl.yml "
14
+ const base = ".mygcl"
15
15
16
16
const defaultBinaryName = "gcl-custom"
17
17
@@ -94,7 +94,7 @@ type Plugin struct {
94
94
}
95
95
96
96
func LoadConfiguration () (* Configuration , error ) {
97
- _ , err := os . Stat ( configFilePath )
97
+ configFilePath , err := findConfigurationFile ( )
98
98
if err != nil {
99
99
return nil , fmt .Errorf ("file %s not found: %w" , configFilePath , err )
100
100
}
@@ -113,3 +113,27 @@ func LoadConfiguration() (*Configuration, error) {
113
113
114
114
return & cfg , nil
115
115
}
116
+
117
+ func findConfigurationFile () (string , error ) {
118
+ entries , err := os .ReadDir ("." )
119
+ if err != nil {
120
+ return "" , fmt .Errorf ("read directory: %w" , err )
121
+ }
122
+
123
+ for _ , entry := range entries {
124
+ ext := filepath .Ext (entry .Name ())
125
+
126
+ switch strings .ToLower (strings .TrimPrefix (ext , "." )) {
127
+ case "yml" , "yaml" , "json" :
128
+ if isConf (ext , entry .Name ()) {
129
+ return entry .Name (), nil
130
+ }
131
+ }
132
+ }
133
+
134
+ return "" , errors .New ("configuration file not found" )
135
+ }
136
+
137
+ func isConf (ext , name string ) bool {
138
+ return base + ext == name
139
+ }
0 commit comments