From 6427b1e64a146047ced3c829a3b877b8d191f642 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 13 Oct 2021 11:54:33 -0400 Subject: [PATCH] tui: make app config take server config --- internal/config/config.go | 29 +++++++++++++------------- internal/config/git.go | 10 ++------- internal/tui/bubbles/commits/bubble.go | 2 +- internal/tui/session.go | 4 +--- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index cd71ee9f3..741c7a625 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,8 +9,8 @@ import ( "os" "path/filepath" + "github.com/charmbracelet/soft/config" "github.com/charmbracelet/soft/internal/git" - "github.com/charmbracelet/soft/stats" gg "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" ) @@ -24,7 +24,7 @@ type Config struct { Users []User `yaml:"users"` Repos []Repo `yaml:"repos"` Source *git.RepoSource - Stats stats.Stats + Cfg *config.Config } type User struct { @@ -41,19 +41,20 @@ type Repo struct { Private bool `yaml:"private"` } -func (cfg *Config) WithStats(s stats.Stats) *Config { - cfg.Stats = s - return cfg -} - -func NewConfig(host string, port int, pk string, rs *git.RepoSource) (*Config, error) { +func NewConfig(cfg *config.Config) (*Config, error) { var anonAccess string var yamlUsers string var displayHost string - cfg := &Config{} - cfg.Host = host - cfg.Port = port - cfg.Source = rs + host := cfg.Host + port := cfg.Port + pk := cfg.InitialAdminKey + rs := cfg.RepoSource + c := &Config{ + Cfg: cfg, + } + c.Host = cfg.Host + c.Port = port + c.Source = rs if pk == "" { anonAccess = "read-write" } else { @@ -75,11 +76,11 @@ func NewConfig(host string, port int, pk string, rs *git.RepoSource) (*Config, e yamlUsers = defaultUserConfig } yaml := fmt.Sprintf("%s%s%s", yamlConfig, yamlUsers, exampleUserConfig) - err := cfg.createDefaultConfigRepo(yaml) + err := c.createDefaultConfigRepo(yaml) if err != nil { return nil, err } - return cfg, nil + return c, nil } func (cfg *Config) reload() error { diff --git a/internal/config/git.go b/internal/config/git.go index 40ded971a..845c2fb8a 100644 --- a/internal/config/git.go +++ b/internal/config/git.go @@ -9,21 +9,15 @@ import ( ) func (cfg *Config) Push(repo string, pk ssh.PublicKey) { - log.Printf("git push: %s", repo) err := cfg.reload() if err != nil { log.Printf("error reloading after push: %s", err) } - if cfg.Stats != nil { - cfg.Stats.Push() - } + cfg.Cfg.Stats.Push(repo) } func (cfg *Config) Fetch(repo string, pk ssh.PublicKey) { - log.Printf("git fetch: %s", repo) - if cfg.Stats != nil { - cfg.Stats.Fetch() - } + cfg.Cfg.Stats.Fetch(repo) } func (cfg *Config) AuthRepo(repo string, pk ssh.PublicKey) gm.AccessLevel { diff --git a/internal/tui/bubbles/commits/bubble.go b/internal/tui/bubbles/commits/bubble.go index 662304a11..205daa701 100644 --- a/internal/tui/bubbles/commits/bubble.go +++ b/internal/tui/bubbles/commits/bubble.go @@ -1,11 +1,11 @@ package commits import ( - "soft-serve/server/git" "strings" "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/soft/internal/git" "github.com/dustin/go-humanize" ) diff --git a/internal/tui/session.go b/internal/tui/session.go index 8bdd5c5d5..9f3cb3951 100644 --- a/internal/tui/session.go +++ b/internal/tui/session.go @@ -27,9 +27,7 @@ func SessionHandler(cfg *config.Config) func(ssh.Session) (tea.Model, []tea.Prog } scfg.Width = pty.Window.Width scfg.Height = pty.Window.Height - if cfg.Stats != nil { - cfg.Stats.Tui() - } + cfg.Cfg.Stats.Tui("view") return NewBubble(cfg, scfg), []tea.ProgramOption{tea.WithAltScreen()} } }