diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-29 11:37:15 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-04 09:07:15 +1100 |
commit | 18ab08612687b34ccfccd0b8d12d8d73e38b8857 (patch) | |
tree | 268bb3b9872e20c75d81102c6ebffdea0e6d6819 /pkg/app | |
parent | b4c078d565af69bcb2f46adc20e528e53ae32908 (diff) |
introduce Common struct for passing around common stuff
Diffstat (limited to 'pkg/app')
-rw-r--r-- | pkg/app/app.go | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index d4e3e15f7..9fae9e2d0 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -17,6 +17,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/env" "github.com/jesseduffield/lazygit/pkg/gui" @@ -27,14 +28,12 @@ import ( // App struct type App struct { - closers []io.Closer - + *common.Common + closers []io.Closer Config config.AppConfigurer - Log *logrus.Entry OSCommand *oscommands.OSCommand GitCommand *commands.GitCommand Gui *gui.Gui - Tr *i18n.TranslationSet Updater *updates.Updater // may only need this on the Gui ClientContext string } @@ -97,27 +96,33 @@ func newLogger(config config.AppConfigurer) *logrus.Entry { // NewApp bootstrap a new application func NewApp(config config.AppConfigurer, filterPath string) (*App, error) { - app := &App{ closers: []io.Closer{}, Config: config, } var err error - app.Log = newLogger(config) - app.Tr, err = i18n.NewTranslationSetFromConfig(app.Log, config.GetUserConfig().Gui.Language) + log := newLogger(config) + tr, err := i18n.NewTranslationSetFromConfig(log, config.GetUserConfig().Gui.Language) if err != nil { return app, err } + app.Common = &common.Common{ + Log: log, + Tr: tr, + UserConfig: config.GetUserConfig(), + Debug: config.GetDebug(), + } + // if we are being called in 'demon' mode, we can just return here app.ClientContext = os.Getenv("LAZYGIT_CLIENT_COMMAND") if app.ClientContext != "" { return app, nil } - app.OSCommand = oscommands.NewOSCommand(app.Log, config) + app.OSCommand = oscommands.NewOSCommand(app.Common) - app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr) + app.Updater, err = updates.NewUpdater(log, config, app.OSCommand, app.Tr) if err != nil { return app, err } @@ -128,9 +133,8 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) { } app.GitCommand, err = commands.NewGitCommand( - app.Log, + app.Common, app.OSCommand, - app.Tr, app.Config, git_config.NewStdCachedGitConfig(app.Log), ) @@ -138,7 +142,7 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) { return app, err } - app.Gui, err = gui.NewGui(app.Log, app.GitCommand, app.OSCommand, app.Tr, config, app.Updater, filterPath, showRecentRepos) + app.Gui, err = gui.NewGui(app.Common, app.GitCommand, app.OSCommand, config, app.Updater, filterPath, showRecentRepos) if err != nil { return app, err } |