Change summary
config/config.go | 16 +++++++++++-----
internal/config/git.go | 8 ++++++--
internal/tui/session.go | 4 +++-
stats/stats.go | 28 ----------------------------
4 files changed, 20 insertions(+), 36 deletions(-)
Detailed changes
@@ -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
}
@@ -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 {
@@ -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()}
}
}
@@ -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{}
-}