mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
refactoring the config struct
This commit is contained in:
parent
01ea5813a8
commit
192a548c99
@ -96,13 +96,15 @@ func newLogger(config config.AppConfigurer) *logrus.Entry {
|
||||
|
||||
// NewApp bootstrap a new application
|
||||
func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
||||
userConfig := config.GetUserConfig()
|
||||
|
||||
app := &App{
|
||||
closers: []io.Closer{},
|
||||
Config: config,
|
||||
}
|
||||
var err error
|
||||
log := newLogger(config)
|
||||
tr, err := i18n.NewTranslationSetFromConfig(log, config.GetUserConfig().Gui.Language)
|
||||
tr, err := i18n.NewTranslationSetFromConfig(log, userConfig.Gui.Language)
|
||||
if err != nil {
|
||||
return app, err
|
||||
}
|
||||
@ -110,7 +112,7 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
||||
app.Common = &common.Common{
|
||||
Log: log,
|
||||
Tr: tr,
|
||||
UserConfig: config.GetUserConfig(),
|
||||
UserConfig: userConfig,
|
||||
Debug: config.GetDebug(),
|
||||
}
|
||||
|
||||
@ -122,7 +124,7 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
||||
|
||||
app.OSCommand = oscommands.NewOSCommand(app.Common)
|
||||
|
||||
app.Updater, err = updates.NewUpdater(log, config, app.OSCommand, app.Tr)
|
||||
app.Updater, err = updates.NewUpdater(app.Common, config, app.OSCommand)
|
||||
if err != nil {
|
||||
return app, err
|
||||
}
|
||||
@ -135,7 +137,6 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
||||
app.GitCommand, err = commands.NewGitCommand(
|
||||
app.Common,
|
||||
app.OSCommand,
|
||||
app.Config,
|
||||
git_config.NewStdCachedGitConfig(app.Log),
|
||||
)
|
||||
if err != nil {
|
||||
@ -207,7 +208,7 @@ func (app *App) setupRepo() (bool, error) {
|
||||
}
|
||||
|
||||
shouldInitRepo := true
|
||||
notARepository := app.Config.GetUserConfig().NotARepository
|
||||
notARepository := app.UserConfig.NotARepository
|
||||
if notARepository == "prompt" {
|
||||
// Offer to initialize a new repository in current directory.
|
||||
fmt.Print(app.Tr.CreateRepo)
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/env"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
@ -49,7 +48,6 @@ type GitCommand struct {
|
||||
func NewGitCommand(
|
||||
cmn *common.Common,
|
||||
osCommand *oscommands.OSCommand,
|
||||
config config.AppConfigurer,
|
||||
gitConfig git_config.IGitConfig,
|
||||
) (*GitCommand, error) {
|
||||
var repo *gogit.Repository
|
||||
|
@ -10,8 +10,6 @@ import (
|
||||
gogit "github.com/jesseduffield/go-git/v5"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -210,8 +208,7 @@ func TestNewGitCommand(t *testing.T) {
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
s.setup()
|
||||
newAppConfig := config.NewDummyAppConfig()
|
||||
s.test(NewGitCommand(utils.NewDummyLog(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language), newAppConfig, git_config.NewFakeGitConfig(nil)))
|
||||
s.test(NewGitCommand(utils.NewDummyCommon(), oscommands.NewDummyOSCommand(), git_config.NewFakeGitConfig(nil)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -31,18 +31,21 @@ type AppConfig struct {
|
||||
// from AppConfig and still be used by lazygit.
|
||||
type AppConfigurer interface {
|
||||
GetDebug() bool
|
||||
|
||||
// build info
|
||||
GetVersion() string
|
||||
GetCommit() string
|
||||
GetBuildDate() string
|
||||
GetName() string
|
||||
GetBuildSource() string
|
||||
|
||||
GetUserConfig() *UserConfig
|
||||
GetUserConfigPaths() []string
|
||||
GetUserConfigDir() string
|
||||
ReloadUserConfig() error
|
||||
|
||||
GetAppState() *AppState
|
||||
SaveAppState() error
|
||||
ReloadUserConfig() error
|
||||
ShowCommandLogOnStartup() bool
|
||||
}
|
||||
|
||||
// NewAppConfig makes a new app config
|
||||
@ -255,17 +258,6 @@ func (c *AppConfig) SaveAppState() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// originally we could only hide the command log permanently via the config
|
||||
// but now we do it via state. So we need to still support the config for the
|
||||
// sake of backwards compatibility
|
||||
func (c *AppConfig) ShowCommandLogOnStartup() bool {
|
||||
if !c.UserConfig.Gui.ShowCommandLog {
|
||||
return false
|
||||
}
|
||||
|
||||
return !c.AppState.HideCommandLog
|
||||
}
|
||||
|
||||
// loadAppState loads recorded AppState from file
|
||||
func loadAppState() (*AppState, error) {
|
||||
filepath, err := configFilePath("state.yml")
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
"github.com/jesseduffield/lazygit/pkg/updates"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
@ -12,7 +11,7 @@ import (
|
||||
// NewDummyGui creates a new dummy GUI for testing
|
||||
func NewDummyUpdater() *updates.Updater {
|
||||
newAppConfig := config.NewDummyAppConfig()
|
||||
dummyUpdater, _ := updates.NewUpdater(utils.NewDummyLog(), newAppConfig, oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language))
|
||||
dummyUpdater, _ := updates.NewUpdater(utils.NewDummyCommon(), newAppConfig, oscommands.NewDummyOSCommand())
|
||||
return dummyUpdater
|
||||
}
|
||||
|
||||
|
@ -432,6 +432,7 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
|
||||
// for now the split view will always be on
|
||||
// NewGui builds a new gui handler
|
||||
func NewGui(cmn *common.Common, gitCommand *commands.GitCommand, oSCommand *oscommands.OSCommand, config config.AppConfigurer, updater *updates.Updater, filterPath string, showRecentRepos bool) (*Gui, error) {
|
||||
|
||||
gui := &Gui{
|
||||
Common: cmn,
|
||||
GitCommand: gitCommand,
|
||||
@ -444,8 +445,12 @@ func NewGui(cmn *common.Common, gitCommand *commands.GitCommand, oSCommand *osco
|
||||
RepoPathStack: []string{},
|
||||
RepoStateMap: map[Repo]*guiState{},
|
||||
CmdLog: []string{},
|
||||
ShowExtrasWindow: config.ShowCommandLogOnStartup(),
|
||||
suggestionsAsyncHandler: tasks.NewAsyncHandler(),
|
||||
|
||||
// originally we could only hide the command log permanently via the config
|
||||
// but now we do it via state. So we need to still support the config for the
|
||||
// sake of backwards compatibility. We're making use of short circuiting here
|
||||
ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog,
|
||||
}
|
||||
|
||||
gui.resetState(filterPath, false)
|
||||
|
@ -73,7 +73,7 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
newGitCommand, err := commands.NewGitCommand(gui.Common, gui.OSCommand, gui.Config, git_config.NewStdCachedGitConfig(gui.Log))
|
||||
newGitCommand, err := commands.NewGitCommand(gui.Common, gui.OSCommand, git_config.NewStdCachedGitConfig(gui.Log))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -16,19 +16,17 @@ import (
|
||||
"github.com/kardianos/osext"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/constants"
|
||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Updater checks for updates and does updates
|
||||
type Updater struct {
|
||||
Log *logrus.Entry
|
||||
*common.Common
|
||||
Config config.AppConfigurer
|
||||
OSCommand *oscommands.OSCommand
|
||||
Tr *i18n.TranslationSet
|
||||
}
|
||||
|
||||
// Updaterer implements the check and update methods
|
||||
@ -38,14 +36,11 @@ type Updaterer interface {
|
||||
}
|
||||
|
||||
// NewUpdater creates a new updater
|
||||
func NewUpdater(log *logrus.Entry, config config.AppConfigurer, osCommand *oscommands.OSCommand, tr *i18n.TranslationSet) (*Updater, error) {
|
||||
contextLogger := log.WithField("context", "updates")
|
||||
|
||||
func NewUpdater(cmn *common.Common, config config.AppConfigurer, osCommand *oscommands.OSCommand) (*Updater, error) {
|
||||
return &Updater{
|
||||
Log: contextLogger,
|
||||
Common: cmn,
|
||||
Config: config,
|
||||
OSCommand: osCommand,
|
||||
Tr: tr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -177,7 +172,7 @@ func (u *Updater) skipUpdateCheck() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
userConfig := u.Config.GetUserConfig()
|
||||
userConfig := u.UserConfig
|
||||
if userConfig.Update.Method == "never" {
|
||||
u.Log.Info("Update method is set to never so we won't check for an update")
|
||||
return true
|
||||
|
@ -18,10 +18,9 @@ func NewDummyLog() *logrus.Entry {
|
||||
|
||||
func NewDummyCommon() *common.Common {
|
||||
tr := i18n.EnglishTranslationSet()
|
||||
newAppConfig := config.NewDummyAppConfig()
|
||||
return &common.Common{
|
||||
Log: NewDummyLog(),
|
||||
Tr: &tr,
|
||||
UserConfig: newAppConfig.GetUserConfig(),
|
||||
UserConfig: config.GetDefaultConfig(),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user