Skip to content

Commit

Permalink
better handle go.mod finding
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Nov 5, 2024
1 parent 3d7c547 commit 91ad317
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ func GetBabylonVersion() (string, error) {
}

fmt.Println("Current working directory:", dir)
goModPath := filepath.Join("..", "go.mod")
data, err := os.ReadFile(goModPath)
if err != nil {
return "", err
goModPaths := []string{filepath.Join("go.mod"), filepath.Join("..", "go.mod")}

var data []byte
for _, goModPath := range goModPaths {
data, err = os.ReadFile(goModPath)
if err != nil {
continue
}
}

if data == nil {
return "", fmt.Errorf("go.mod not found")
}

// Parse the go.mod file
Expand Down

0 comments on commit 91ad317

Please sign in to comment.