diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-01 14:33:01 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-01 14:33:01 +1000 |
commit | d31520261f0ffc4cb93e29476e39ace45e813fc8 (patch) | |
tree | 8ebf28daf9937ccd1ade4882686253ac2a04fbb6 /pkg/config | |
parent | ad880e2d56cd9ab3841dd077d47979202c509460 (diff) |
introduce platform specific defaults
Diffstat (limited to 'pkg/config')
-rw-r--r-- | pkg/config/app_config.go | 20 | ||||
-rw-r--r-- | pkg/config/config_default_platform.go | 10 | ||||
-rw-r--r-- | pkg/config/config_linux.go | 8 | ||||
-rw-r--r-- | pkg/config/config_windows.go | 8 |
4 files changed, 35 insertions, 11 deletions
diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index b5503d6fd..3e384d80f 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -40,8 +40,7 @@ type AppConfigurer interface { // NewAppConfig makes a new app config func NewAppConfig(name, version, commit, date string, buildSource string, debuggingFlag *bool) (*AppConfig, error) { - defaultConfig := GetDefaultConfig() - userConfig, err := LoadConfig("config", defaultConfig) + userConfig, err := LoadConfig("config", true) if err != nil { return nil, err } @@ -113,13 +112,16 @@ func newViper(filename string) (*viper.Viper, error) { } // LoadConfig gets the user's config -func LoadConfig(filename string, defaults []byte) (*viper.Viper, error) { +func LoadConfig(filename string, withDefaults bool) (*viper.Viper, error) { v, err := newViper(filename) if err != nil { return nil, err } - if defaults != nil { - if err = LoadDefaults(v, defaults); err != nil { + if withDefaults { + if err = LoadDefaults(v, GetDefaultConfig()); err != nil { + return nil, err + } + if err = LoadDefaults(v, GetPlatformDefaultConfig()); err != nil { return nil, err } } @@ -131,7 +133,7 @@ func LoadConfig(filename string, defaults []byte) (*viper.Viper, error) { // LoadDefaults loads in the defaults defined in this file func LoadDefaults(v *viper.Viper, defaults []byte) error { - return v.ReadConfig(bytes.NewBuffer(defaults)) + return v.MergeConfig(bytes.NewBuffer(defaults)) } func prepareConfigFile(filename string) (string, error) { @@ -166,7 +168,7 @@ func LoadAndMergeFile(v *viper.Viper, filename string) error { func (c *AppConfig) WriteToUserConfig(key, value string) error { // reloading the user config directly (without defaults) so that we're not // writing any defaults back to the user's config - v, err := LoadConfig("config", nil) + v, err := LoadConfig("config", false) if err != nil { return err } @@ -222,10 +224,6 @@ update: method: prompt # can be: prompt | background | never days: 14 # how often a update is checked for reporting: 'undetermined' # one of: 'on' | 'off' | 'undetermined' -# git: -# stuff relating to git -# os: -# openCommand: 'code -r {{filename}}' `) } diff --git a/pkg/config/config_default_platform.go b/pkg/config/config_default_platform.go new file mode 100644 index 000000000..a87d5a7f6 --- /dev/null +++ b/pkg/config/config_default_platform.go @@ -0,0 +1,10 @@ +// +build !windows !linux + +package config + +// GetPlatformDefaultConfig gets the defaults for the platform +func GetPlatformDefaultConfig() []byte { + return []byte( + `os: + openCommand: 'open {{filename}}'`) +} diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go new file mode 100644 index 000000000..ef30ac7d2 --- /dev/null +++ b/pkg/config/config_linux.go @@ -0,0 +1,8 @@ +package config + +// GetPlatformDefaultConfig gets the defaults for the platform +func GetPlatformDefaultConfig() []byte { + return []byte( + `os: + openCommand: 'bash -c \"xdg-open {{filename}} &>/dev/null &\"'`) +} diff --git a/pkg/config/config_windows.go b/pkg/config/config_windows.go new file mode 100644 index 000000000..b81a5fdb5 --- /dev/null +++ b/pkg/config/config_windows.go @@ -0,0 +1,8 @@ +package config + +// GetPlatformDefaultConfig gets the defaults for the platform +func GetPlatformDefaultConfig() []byte { + return []byte( + `os: + openCommand: 'cmd /c "start "" {{filename}}"'`) +} |