refactor: do not merge settings

This feature no longer serves its purpose
This commit is contained in:
Jan De Dobbeleer 2020-09-20 19:33:55 +02:00 committed by Jan De Dobbeleer
parent 2603ff51bf
commit 8a3f330af4
3 changed files with 9 additions and 23 deletions

9
Gopkg.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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 {