diff --git a/config/config.go b/config/config.go index 160e71120..897bd014d 100644 --- a/config/config.go +++ b/config/config.go @@ -3,10 +3,16 @@ package config import ( "log" - "github.com/charmbracelet/soft/stats" "github.com/meowgorithm/babyenv" ) +// Callbacks provides an interface that can be used to run callbacks on different events. +type Callbacks interface { + Tui(action string) + Push(repo string) + Fetch(repo string) +} + // Config is the configuration for the soft-serve. type Config struct { Host string `env:"SOFT_SERVE_HOST" default:""` @@ -14,7 +20,7 @@ type Config struct { KeyPath string `env:"SOFT_SERVE_KEY_PATH" default:".ssh/soft_serve_server_ed25519"` RepoPath string `env:"SOFT_SERVE_REPO_PATH" default:".repos"` InitialAdminKey string `env:"SOFT_SERVE_INITIAL_ADMIN_KEY" default:""` - Stats stats.Stats + Callbacks Callbacks } // DefaultConfig returns a Config with the values populated with the defaults @@ -25,10 +31,10 @@ func DefaultConfig() *Config { if err != nil { log.Fatalln(err) } - return scfg.WithStats(stats.NewStats()) + return scfg.WithCallbacks(nil) } -func (cfg *Config) WithStats(s stats.Stats) *Config { - cfg.Stats = s +func (cfg *Config) WithCallbacks(c Callbacks) *Config { + cfg.Callbacks = c return cfg } diff --git a/internal/config/git.go b/internal/config/git.go index 845c2fb8a..6832455b4 100644 --- a/internal/config/git.go +++ b/internal/config/git.go @@ -13,11 +13,15 @@ func (cfg *Config) Push(repo string, pk ssh.PublicKey) { if err != nil { log.Printf("error reloading after push: %s", err) } - cfg.Cfg.Stats.Push(repo) + if cfg.Cfg.Callbacks != nil { + cfg.Cfg.Callbacks.Push(repo) + } } func (cfg *Config) Fetch(repo string, pk ssh.PublicKey) { - cfg.Cfg.Stats.Fetch(repo) + if cfg.Cfg.Callbacks != nil { + cfg.Cfg.Callbacks.Fetch(repo) + } } func (cfg *Config) AuthRepo(repo string, pk ssh.PublicKey) gm.AccessLevel { diff --git a/internal/tui/session.go b/internal/tui/session.go index 9f3cb3951..9f2c48600 100644 --- a/internal/tui/session.go +++ b/internal/tui/session.go @@ -27,7 +27,9 @@ func SessionHandler(cfg *config.Config) func(ssh.Session) (tea.Model, []tea.Prog } scfg.Width = pty.Window.Width scfg.Height = pty.Window.Height - cfg.Cfg.Stats.Tui("view") + if cfg.Cfg.Callbacks != nil { + cfg.Cfg.Callbacks.Tui("view") + } return NewBubble(cfg, scfg), []tea.ProgramOption{tea.WithAltScreen()} } } diff --git a/stats/stats.go b/stats/stats.go deleted file mode 100644 index b9eb71736..000000000 --- a/stats/stats.go +++ /dev/null @@ -1,28 +0,0 @@ -package stats - -import "log" - -// Stats provides an interface that can be used to collect metrics about the server. -type Stats interface { - Tui(action string) - Push(repo string) - Fetch(repo string) -} - -type stats struct{} - -func (s *stats) Tui(action string) { - log.Printf("TUI: %s", action) -} - -func (s *stats) Push(repo string) { - log.Printf("git push: %s", repo) -} - -func (s *stats) Fetch(repo string) { - log.Printf("git fetch: %s", repo) -} - -func NewStats() Stats { - return &stats{} -}