From 8a3f330af434457fc876cdfb15c644a259946c8d Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 20 Sep 2020 19:33:55 +0200 Subject: [PATCH] refactor: do not merge settings This feature no longer serves its purpose --- Gopkg.lock | 9 --------- Gopkg.toml | 4 ---- settings.go | 19 +++++++++---------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index b9256c82..79ef0856 100755 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -27,14 +27,6 @@ revision = "c52faac6396f15fd78c8fd343657f514b60a1147" source = "github.com/JanDeDobbeleer/color" -[[projects]] - digest = "1:eba10af56a904e7d797ccbdca4a6fae4029537b0118b6582f9f93e025b86af2a" - name = "github.com/imdario/mergo" - packages = ["."] - pruneopts = "UT" - revision = "cd55aeac72a19c6d5826061d5125d72b252a12eb" - version = "v0.3.11" - [[projects]] digest = "1:69530a15507094162be4eb3180c1d68b787177e8c9bbe76d4da40d44d6586f6f" name = "github.com/mitchellh/go-ps" @@ -122,7 +114,6 @@ input-imports = [ "github.com/distatus/battery", "github.com/gookit/color", - "github.com/imdario/mergo", "github.com/mitchellh/go-ps", "github.com/stretchr/testify/assert", "github.com/stretchr/testify/mock", diff --git a/Gopkg.toml b/Gopkg.toml index 0c73d068..cc6feb4f 100755 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -34,10 +34,6 @@ name = "golang.org/x/text" source = "golang.org/x/text" -[[constraint]] - version = "v0.3.7" - name = "github.com/imdario/mergo" - [[constraint]] name = "github.com/stretchr/testify" version = "1.3.0" diff --git a/settings.go b/settings.go index 7b842493..cc535dba 100755 --- a/settings.go +++ b/settings.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" "os" - - "github.com/imdario/mergo" ) //Settings holds all the theme for rendering the prompt @@ -45,15 +43,16 @@ type Block struct { //GetSettings returns the default configuration including possible user overrides func GetSettings(env environmentInfo) *Settings { - defaultSettings := getDefaultSettings() - settings := loadUserConfiguration(env) - _ = mergo.Merge(settings, defaultSettings) + settings, err := loadUserConfiguration(env) + if err != nil { + return getDefaultSettings() + } return settings } -func loadUserConfiguration(env environmentInfo) *Settings { +func loadUserConfiguration(env environmentInfo) (*Settings, error) { var settings Settings - settingsFileLocation := fmt.Sprintf("%s/.go_my_psh", env.getenv("HOME")) + settingsFileLocation := fmt.Sprintf("%s/.go_my_posh", env.getenv("HOME")) if _, err := os.Stat(*env.getArgs().Config); !os.IsNotExist(err) { settingsFileLocation = *env.getArgs().Config } @@ -62,11 +61,11 @@ func loadUserConfiguration(env environmentInfo) *Settings { _ = defaultSettings.Close() }() if err != nil { - return &settings + return nil, err } jsonParser := json.NewDecoder(defaultSettings) - _ = jsonParser.Decode(&settings) - return &settings + err = jsonParser.Decode(&settings) + return &settings, err } func getDefaultSettings() *Settings {