Skip to content

Commit

Permalink
setup config default in load config
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Oct 9, 2021
1 parent 516bd18 commit bd39661
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var rootCmd = &cobra.Command{
Version: "0.5.4",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
config.SetDefaults()
config.LoadConfig()

cfg := config.GetConfig()
Expand Down
21 changes: 9 additions & 12 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func LoadConfig() {
viper.SetConfigName(".fm")
viper.SetConfigType("yml")

// Setup config default.
viper.SetDefault("settings.start_dir", ".")
viper.SetDefault("settings.show_icons", true)
viper.SetDefault("settings.enable_logging", false)
viper.SetDefault("settings.enable_mousewheel", true)
viper.SetDefault("settings.pretty_markdown", true)
viper.SetDefault("settings.borderless", false)
viper.SetDefault("settings.theme", "default")

if err := viper.SafeWriteConfig(); err != nil {
if os.IsNotExist(err) {
err = viper.WriteConfig()
Expand All @@ -54,15 +63,3 @@ func GetConfig() (config Config) {

return
}

// SetDefaults sets default values for the config.
func SetDefaults() {
// App Settings.
viper.SetDefault("settings.start_dir", ".")
viper.SetDefault("settings.show_icons", true)
viper.SetDefault("settings.enable_logging", false)
viper.SetDefault("settings.enable_mousewheel", true)
viper.SetDefault("settings.pretty_markdown", true)
viper.SetDefault("settings.borderless", false)
viper.SetDefault("settings.theme", "default")
}

0 comments on commit bd39661

Please sign in to comment.