diff --git a/src/cmd/main.go b/src/cmd/main.go index 821d5563..24cac495 100644 --- a/src/cmd/main.go +++ b/src/cmd/main.go @@ -53,6 +53,12 @@ func Run(content embed.FS) { Usage: "Adds any missing hotkeys to the hotkey config file", Value: false, }, + &cli.BoolFlag{ + Name: "fix-config-file", + Aliases: []string{"fch"}, + Usage: "Adds any missing hotkeys to the hotkey config file", + Value: false, + }, }, Action: func(c *cli.Context) error { path := "" @@ -63,6 +69,7 @@ func Run(content embed.FS) { InitConfigFile() variable.FixHotkeys = c.Bool("fix-hotkeys") + variable.FixConfigFile = c.Bool("fix-config-file") firstUse := checkFirstUse() @@ -74,6 +81,7 @@ func Run(content embed.FS) { CheckForUpdates() return nil }, + } err := app.Run(os.Args) diff --git a/src/config/fixed_variable.go b/src/config/fixed_variable.go index 84e49924..9b6c7a1e 100644 --- a/src/config/fixed_variable.go +++ b/src/config/fixed_variable.go @@ -25,6 +25,7 @@ var ( ToggleDotFile string = SuperFileDataDir + "/toggleDotFile" LogFile string = SuperFileStateDir + "/superfile.log" FixHotkeys bool = false + FixConfigFile bool = false ) const ( diff --git a/src/internal/config_function.go b/src/internal/config_function.go index a0a18fe1..9fa8a88e 100644 --- a/src/internal/config_function.go +++ b/src/internal/config_function.go @@ -76,8 +76,11 @@ func loadConfigFile() { _ = toml.Unmarshal(data, &tempForCheckMissingConfig) err = toml.Unmarshal(data, &Config) - if err != nil { - log.Fatalf("Error decoding config file ( your config file may have misconfigured ): %v", err) + if err != nil && !variable.FixConfigFile { + fmt.Print(lipgloss.NewStyle().Foreground(lipgloss.Color("#F93939")).Render("Error") + + lipgloss.NewStyle().Foreground(lipgloss.Color("#00FFEE")).Render(" ┃ ") + + "Error decoding configuration file\n") + fmt.Println("To add missing fields to hotkeys directory automaticially run Superfile with the --fix-config-file flag `spf --fix-config-file`") } if !reflect.DeepEqual(Config, tempForCheckMissingConfig) { @@ -86,9 +89,11 @@ func loadConfigFile() { log.Fatalf("Error encoding config: %v", err) } - err = os.WriteFile(variable.ConfigFile, tomlData, 0644) - if err != nil { - log.Fatalf("Error writing config file: %v", err) + if variable.FixConfigFile { + err = os.WriteFile(variable.ConfigFile, tomlData, 0644) + if err != nil { + log.Fatalf("Error writing config file: %v", err) + } } } if (Config.FilePreviewWidth > 10 || Config.FilePreviewWidth < 2) && Config.FilePreviewWidth != 0 { @@ -133,7 +138,7 @@ func loadHotkeysFile() { fmt.Sprintf("Field \"%s\" is missing in hotkeys configuration\n", name)) } } - fmt.Println("To add missing fields to hotkeys directory automaticially run Superfile with the --fix-hotkeys flag") + fmt.Println("To add missing fields to hotkeys directory automaticially run Superfile with the --fix-hotkeys flag `spf --fix-hotkeys`") } if hasMissingHotkeysInConfig && variable.FixHotkeys {