Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Vaumoron <[email protected]>
  • Loading branch information
dvaumoron committed Jun 30, 2024
1 parent 16dd438 commit 78d4eba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 2 additions & 8 deletions versionmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package versionmanager

import (
"bytes"
"errors"
"io/fs"
"os"
Expand Down Expand Up @@ -221,14 +220,9 @@ func (m VersionManager) ReadDefaultConstraint() string {
return constraint
}

data, err := os.ReadFile(m.RootConstraintFilePath())
if err != nil {
m.conf.Displayer.Log(loghelper.LevelWarnOrDebug(errors.Is(err, fs.ErrNotExist)), "Failed to read file", loghelper.Error, err)

return ""
}
constraint, _ := flatparser.Retrieve(m.RootConstraintFilePath(), m.conf, flatparser.NoMsg)

return string(bytes.TrimSpace(data))
return constraint
}

func (m VersionManager) ResetConstraint() error {
Expand Down
12 changes: 10 additions & 2 deletions versionmanager/semantic/parser/flat/flatparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import (
"github.com/tofuutils/tenv/v2/versionmanager/semantic/types"
)

func RetrieveVersion(filePath string, conf *config.Config) (string, error) {
func NoMsg(_ loghelper.Displayer, value string, _ string) string {
return value
}

func Retrieve(filePath string, conf *config.Config, displayMsg func(loghelper.Displayer, string, string) string) (string, error) {
data, err := os.ReadFile(filePath)
if err != nil {
conf.Displayer.Log(loghelper.LevelWarnOrDebug(errors.Is(err, fs.ErrNotExist)), "Failed to read file", loghelper.Error, err)
Expand All @@ -42,5 +46,9 @@ func RetrieveVersion(filePath string, conf *config.Config) (string, error) {
return "", nil
}

return types.DisplayDetectionInfo(conf.Displayer, resolvedVersion, filePath), nil
return displayMsg(conf.Displayer, resolvedVersion, filePath), nil
}

func RetrieveVersion(filePath string, conf *config.Config) (string, error) {
return Retrieve(filePath, conf, types.DisplayDetectionInfo)
}

0 comments on commit 78d4eba

Please sign in to comment.