Skip to content

Commit

Permalink
Rename Stats interface to Callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 18, 2021
1 parent 86140b2 commit 031d796
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 36 deletions.
16 changes: 11 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ 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:""`
Port int `env:"SOFT_SERVE_PORT" default:"23231"`
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
Expand All @@ -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
}
8 changes: 6 additions & 2 deletions internal/config/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion internal/tui/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
}
}
28 changes: 0 additions & 28 deletions stats/stats.go

This file was deleted.

0 comments on commit 031d796

Please sign in to comment.