Skip to content

Commit

Permalink
fix: now the repo root .sauced.yaml gets it's contents read
Browse files Browse the repository at this point in the history
  • Loading branch information
nickytonline committed Sep 4, 2024
1 parent ad9e3a0 commit a80a91a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const DefaultConfigPath = "~/.sauced.yaml"
// empty path is provided. If none is found in the user's home directory, it tries to load
// ".sauced.yaml" from the fallback path, which is the root path of a repository.
func LoadConfig(path string, repoRootPathConfig string) (*Spec, error) {
println("Config path loading from -c flag", path)

config := &Spec{}

if path == DefaultConfigPath || path == "" {
Expand All @@ -35,12 +37,20 @@ func LoadConfig(path string, repoRootPathConfig string) (*Spec, error) {

data, err := os.ReadFile(absPath)
if err != nil {
println("Error reading config file", err)
// If the file does not exist, check if the fallback path exists
if os.IsNotExist(err) {
_, err = os.Stat(repoRootPathConfig)

if err != nil {
return nil, fmt.Errorf("error reading config file from %s or %s", absPath, repoRootPathConfig)
}

data, err = os.ReadFile(repoRootPathConfig)

if err != nil {
return nil, fmt.Errorf("error reading config file from %s", repoRootPathConfig)
}
} else {
return nil, fmt.Errorf("error reading config file: %w", err)
}
Expand All @@ -51,5 +61,7 @@ func LoadConfig(path string, repoRootPathConfig string) (*Spec, error) {
return nil, fmt.Errorf("error unmarshaling config: %w", err)
}

fmt.Printf("Loaded config %v", config)

return config, nil
}

0 comments on commit a80a91a

Please sign in to comment.