Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cmd/scaf/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"
"path/filepath"

"github.com/rlch/scaf"
)

// loadConfigWithDir loads config and returns both the config and the directory it was found in.
// Walks up from startDir to find .scaf.yaml.
func loadConfigWithDir(startDir string) (*scaf.Config, string, error) {
dir := startDir
for {
cfg, err := scaf.LoadConfig(dir)
if err == nil {
return cfg, dir, nil
}

parent := filepath.Dir(dir)
if parent == dir {
// Reached root, no config found
return nil, startDir, fmt.Errorf("no .scaf.yaml found")
}
dir = parent
}
}
Loading