From 745ed4cd200d59fff75b08c1f34b4d796d022214 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 22 Sep 2021 17:29:06 -0400 Subject: [PATCH] Return errMsg when config is not set --- tui/bubble.go | 12 ++++++++++-- tui/commands.go | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tui/bubble.go b/tui/bubble.go index 062548ac2..e0ebb9ea6 100644 --- a/tui/bubble.go +++ b/tui/bubble.go @@ -61,12 +61,16 @@ type Bubble struct { } func NewBubble(cfg *Config, sCfg *SessionConfig) *Bubble { + var repoSource *git.RepoSource = nil + if cfg != nil { + repoSource = cfg.RepoSource + } b := &Bubble{ config: cfg, styles: style.DefaultStyles(), width: sCfg.Width, height: sCfg.Height, - repoSource: cfg.RepoSource, + repoSource: repoSource, repoMenu: make([]MenuEntry, 0), boxes: make([]tea.Model, 2), initialRepo: sCfg.InitialRepo, @@ -156,7 +160,11 @@ func (b *Bubble) viewForBox(i int) string { func (b Bubble) headerView() string { w := b.width - b.styles.App.GetHorizontalFrameSize() - return b.styles.Header.Copy().Width(w).Render(b.config.Name) + name := "" + if b.config != nil { + name = b.config.Name + } + return b.styles.Header.Copy().Width(w).Render(name) } func (b Bubble) footerView() string { diff --git a/tui/commands.go b/tui/commands.go index e88856e99..4f7c6d452 100644 --- a/tui/commands.go +++ b/tui/commands.go @@ -19,6 +19,9 @@ func (e errMsg) Error() string { } func (b *Bubble) setupCmd() tea.Msg { + if b.config == nil || b.config.RepoSource == nil { + return errMsg{err: fmt.Errorf("config not set")} + } ct := time.Now() lipgloss.SetColorProfile(termenv.ANSI256) b.repos = b.repoSource.AllRepos()