From 48bb3a9dcefb28be347466c7a3dd0db5e94c7d04 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 14 Jul 2024 14:26:42 +0200 Subject: [PATCH] Make fields of AppConfig private We are going to make a few changes to the fields in this branch, and we can make them with more peace of mind when we can be sure they are not accessed from outside this package. --- pkg/config/app_config.go | 64 ++++++++++++++++++++-------------------- pkg/config/dummies.go | 12 ++++---- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 151a8b65a..dd1635f6f 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -13,16 +13,16 @@ import ( // AppConfig contains the base configuration fields required for lazygit. type AppConfig struct { - Debug bool `long:"debug" env:"DEBUG" default:"false"` - Version string `long:"version" env:"VERSION" default:"unversioned"` - BuildDate string `long:"build-date" env:"BUILD_DATE"` - Name string `long:"name" env:"NAME" default:"lazygit"` - BuildSource string `long:"build-source" env:"BUILD_SOURCE" default:""` - UserConfig *UserConfig - UserConfigPaths []string - UserConfigDir string - TempDir string - AppState *AppState + debug bool `long:"debug" env:"DEBUG" default:"false"` + version string `long:"version" env:"VERSION" default:"unversioned"` + buildDate string `long:"build-date" env:"BUILD_DATE"` + name string `long:"name" env:"NAME" default:"lazygit"` + buildSource string `long:"build-source" env:"BUILD_SOURCE" default:""` + userConfig *UserConfig + userConfigPaths []string + userConfigDir string + tempDir string + appState *AppState } type AppConfigurer interface { @@ -90,16 +90,16 @@ func NewAppConfig( } appConfig := &AppConfig{ - Name: name, - Version: version, - BuildDate: date, - Debug: debuggingFlag, - BuildSource: buildSource, - UserConfig: userConfig, - UserConfigPaths: userConfigPaths, - UserConfigDir: configDir, - TempDir: tempDir, - AppState: appState, + name: name, + version: version, + buildDate: date, + debug: debuggingFlag, + buildSource: buildSource, + userConfig: userConfig, + userConfigPaths: userConfigPaths, + userConfigDir: configDir, + tempDir: tempDir, + appState: appState, } return appConfig, nil @@ -217,53 +217,53 @@ func changeNullKeybindingsToDisabled(changedContent []byte) ([]byte, error) { } func (c *AppConfig) GetDebug() bool { - return c.Debug + return c.debug } func (c *AppConfig) GetVersion() string { - return c.Version + return c.version } func (c *AppConfig) GetName() string { - return c.Name + return c.name } // GetBuildSource returns the source of the build. For builds from goreleaser // this will be binaryBuild func (c *AppConfig) GetBuildSource() string { - return c.BuildSource + return c.buildSource } // GetUserConfig returns the user config func (c *AppConfig) GetUserConfig() *UserConfig { - return c.UserConfig + return c.userConfig } // GetAppState returns the app state func (c *AppConfig) GetAppState() *AppState { - return c.AppState + return c.appState } func (c *AppConfig) GetUserConfigPaths() []string { - return c.UserConfigPaths + return c.userConfigPaths } func (c *AppConfig) GetUserConfigDir() string { - return c.UserConfigDir + return c.userConfigDir } func (c *AppConfig) ReloadUserConfig() error { - userConfig, err := loadUserConfigWithDefaults(c.UserConfigPaths) + userConfig, err := loadUserConfigWithDefaults(c.userConfigPaths) if err != nil { return err } - c.UserConfig = userConfig + c.userConfig = userConfig return nil } func (c *AppConfig) GetTempDir() string { - return c.TempDir + return c.tempDir } // findConfigFile looks for a possibly existing config file. @@ -304,7 +304,7 @@ func stateFilePath(filename string) (string, error) { // SaveAppState marshalls the AppState struct and writes it to the disk func (c *AppConfig) SaveAppState() error { - marshalledAppState, err := yaml.Marshal(c.AppState) + marshalledAppState, err := yaml.Marshal(c.appState) if err != nil { return err } diff --git a/pkg/config/dummies.go b/pkg/config/dummies.go index 077c93c57..06c8755a6 100644 --- a/pkg/config/dummies.go +++ b/pkg/config/dummies.go @@ -7,12 +7,12 @@ import ( // NewDummyAppConfig creates a new dummy AppConfig for testing func NewDummyAppConfig() *AppConfig { appConfig := &AppConfig{ - Name: "lazygit", - Version: "unversioned", - Debug: false, - UserConfig: GetDefaultConfig(), - AppState: &AppState{}, + name: "lazygit", + version: "unversioned", + debug: false, + userConfig: GetDefaultConfig(), + appState: &AppState{}, } - _ = yaml.Unmarshal([]byte{}, appConfig.AppState) + _ = yaml.Unmarshal([]byte{}, appConfig.appState) return appConfig }