Skip to content

Commit cfb5f59

Browse files
committed
feat: support yml, yaml, json as file extension
1 parent ee93d9f commit cfb5f59

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ coverage.xml
2121
/custom-golangci-lint
2222
/gcl-custom
2323
.mygcl.yml
24+
.mygcl.yaml

pkg/commands/internal/configuration.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"gopkg.in/yaml.v3"
1212
)
1313

14-
const configFilePath = ".mygcl.yml"
14+
const base = ".mygcl"
1515

1616
const defaultBinaryName = "gcl-custom"
1717

@@ -94,7 +94,7 @@ type Plugin struct {
9494
}
9595

9696
func LoadConfiguration() (*Configuration, error) {
97-
_, err := os.Stat(configFilePath)
97+
configFilePath, err := findConfigurationFile()
9898
if err != nil {
9999
return nil, fmt.Errorf("file %s not found: %w", configFilePath, err)
100100
}
@@ -113,3 +113,27 @@ func LoadConfiguration() (*Configuration, error) {
113113

114114
return &cfg, nil
115115
}
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

Comments
 (0)