Skip to content

Commit

Permalink
Merge pull request #2 from jeff-roche/configext
Browse files Browse the repository at this point in the history
feat: Configext
  • Loading branch information
jeff-roche authored Jun 2, 2022
2 parents 3ddd04c + 4eaaf95 commit 1100f41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ biome

# Actual biome config (only meant to be exclude from this repo, should be in your own repos)
.biome.yaml
.biome.yml

# Test binary, built with `go test -c`
*.test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $ onstaging ./bin/ci/deploy-service.sh
- :white_check_mark: Implement goreleaser for binary building
- :white_check_mark: Use semantic versioning
- :white_check_mark: Add a version command
- Accept all valid yaml file extensions
- :white_check_mark: Accept all valid yaml file extensions
- Build a Drone CI/CD pipeline
- Implement some tests
- Loading Environment variables from a .env file
Expand Down
20 changes: 11 additions & 9 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import (
)

var LoadedBiome *config.BiomeConfig
const BiomeConfigFileName = ".biome.yaml"
var BiomeConfigFileNames = []string{".biome.yaml", ".biome.yml"}

// LoadBiome will find the nearest .biome.yaml in this priority order
// LoadBiome will find the nearest .biome.[yml|yaml] in this priority order
// - Current Directory
// - Home Directory
func LoadBiome(biomeName string) error {
biomeConfigPaths := []string{
getCdFilePath(),
getHomeDirFilePath(),
getCdFilePath(BiomeConfigFileNames[0]),
getCdFilePath(BiomeConfigFileNames[1]),
getHomeDirFilePath(BiomeConfigFileNames[0]),
getHomeDirFilePath(BiomeConfigFileNames[1]),
}

// Reset the loaded biome
Expand Down Expand Up @@ -95,7 +97,7 @@ func tryLoadBiomeConfig(fPath string, biomeName string) error {
}

func findBiomeInFileContents(data []byte, biomeName string) (*config.BiomeConfig, error) {

// Setup the reader and decoder
r := bytes.NewReader(data)
decoder := yaml.NewDecoder(r)
Expand All @@ -120,22 +122,22 @@ func findBiomeInFileContents(data []byte, biomeName string) (*config.BiomeConfig
return nil, nil
}

func getCdFilePath() string {
func getCdFilePath(fname string) string {
cdPath, err := os.Getwd()
if err != nil {
log.Fatalf("unable to get current directory: %v", err)
}

return path.Join(cdPath, BiomeConfigFileName)
return path.Join(cdPath, fname)
}

func getHomeDirFilePath() string {
func getHomeDirFilePath(fname string) string {
currentUser, err := user.Current()
if err != nil {
log.Fatalf("unable to get current user: %v", err)
}

return path.Join(currentUser.HomeDir, BiomeConfigFileName)
return path.Join(currentUser.HomeDir, fname)
}

func fileExists(path string) bool {
Expand Down

0 comments on commit 1100f41

Please sign in to comment.