-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ProjectDir from config and determine it dynamically when needed
Signed-off-by: Mathieu Frenette <[email protected]>
- Loading branch information
Showing
7 changed files
with
60 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package project | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/Samasource/jen/src/internal/constant" | ||
"github.com/Samasource/jen/src/internal/helpers" | ||
) | ||
|
||
// GetProjectDir returns the project's root dir. It finds it by looking for the jen.yaml file | ||
// in current working dir and then walking up the directory structure until it reaches the | ||
// volume's root dir. If it doesn't find it, it returns an empty string. | ||
func GetProjectDir() (string, error) { | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
return "", fmt.Errorf("finding project's root dir: %w", err) | ||
} | ||
|
||
for { | ||
filePath := path.Join(dir, constant.JenFileName) | ||
if helpers.PathExists(filePath) { | ||
return dir, nil | ||
} | ||
if dir == "/" { | ||
return "", nil | ||
} | ||
dir = path.Dir(dir) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters