~mariusor/motley

83c23c32d11b288be5f3f183482da0aefae61a7a — Marius Orcsik 5 months ago 21d0fd1
Fix run target
5 files changed, 46 insertions(+), 40 deletions(-)

M Makefile
M go.mod
M internal/cmd/cmd.go
M internal/cmd/storage_all.go
M ui.go
M Makefile => Makefile +2 -2
@@ 46,8 46,8 @@ motley: bin/motley
bin/motley: go.mod cmd/main.go $(APPSOURCES)
	$(BUILD) -tags "$(TAGS)" -o $@ ./cmd/

run: motley
	@./bin/motely
run: ./bin/motley
	@./bin/motley

clean:
	-$(RM) bin/*

M go.mod => go.mod +5 -6
@@ 3,6 3,7 @@ module git.sr.ht/~marius/motley
go 1.14

require (
	github.com/DataDog/zstd v1.4.5 // indirect
	github.com/alecthomas/chroma v0.9.1 // indirect
	github.com/atotto/clipboard v0.1.4 // indirect
	github.com/charmbracelet/bubbles v0.7.9


@@ 10,13 11,11 @@ require (
	github.com/charmbracelet/glamour v0.3.0
	github.com/charmbracelet/lipgloss v0.2.1
	github.com/containerd/console v1.0.2 // indirect
	github.com/dlclark/regexp2 v1.4.0 // indirect
	github.com/go-ap/activitypub v0.0.0-20210403114333-558da3636016
	github.com/go-ap/auth v0.0.0-20210113101207-103038d69797
	github.com/go-ap/errors v0.0.0-20200702155720-f662512ba418
	github.com/go-ap/fedbox v0.0.0-20210116130525-fd9377430e3e
	github.com/go-ap/auth v0.0.0-20210403114547-c68fb3011ebd
	github.com/go-ap/errors v0.0.0-20210218123445-4466eca2f4ec
	github.com/go-ap/fedbox v0.0.0-20210415164852-b86be7df20e1
	github.com/go-ap/storage v0.0.0-20210403114403-99ae85c8cc72
	github.com/google/uuid v1.2.0 // indirect
	github.com/joho/godotenv v1.3.0
	github.com/mariusor/bubbles-tree v0.0.0-20210514170659-b437f1f8fd6a
	github.com/mattn/go-runewidth v0.0.12


@@ 24,7 23,7 @@ require (
	github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68
	github.com/muesli/termenv v0.8.1
	github.com/openshift/osin v1.0.1
	github.com/sirupsen/logrus v1.7.0
	github.com/sirupsen/logrus v1.8.1
	github.com/yuin/goldmark v1.3.5 // indirect
	golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
	golang.org/x/net v0.0.0-20210510120150-4163338589ed // indirect

M internal/cmd/cmd.go => internal/cmd/cmd.go +9 -10
@@ 21,10 21,10 @@ var (
type Control struct {
	Conf        config.Options
	AuthStorage osin.Storage
	Storage     storage.Repository
	Storage     storage.Store
}

func New(authDB osin.Storage, actorDb storage.Repository, conf config.Options) *Control {
func New(authDB osin.Storage, actorDb storage.Store, conf config.Options) *Control {
	return &Control{
		Conf:        conf,
		AuthStorage: authDB,


@@ 33,7 33,6 @@ func New(authDB osin.Storage, actorDb storage.Repository, conf config.Options) *
}

func Before(c *cli.Context) error {
	logger.Level = logrus.WarnLevel
	ct, err := setup(c, logger)
	if err != nil {
		// Ensure we don't print the default help message, which is not useful here


@@ 42,13 41,10 @@ func Before(c *cli.Context) error {
		return err
	}
	ctl = *ct
	// the level enums have same values
	logger.Level = logrus.TraceLevel

	return nil
}

func setup(c *cli.Context, l logrus.FieldLogger) (*Control, error) {
func setup(c *cli.Context, l *logrus.Logger) (*Control, error) {
	environ := env.Type(c.String("env"))
	if environ == "" {
		environ = env.DEV


@@ 57,16 53,19 @@ func setup(c *cli.Context, l logrus.FieldLogger) (*Control, error) {
	if err != nil {
		l.Errorf("Unable to load config files for environment %s: %s", environ, err)
	}

	if dir := c.String("path"); dir != "." {
		conf.StoragePath = dir
	}
	typ := c.String("type")
	if typ != "" {
	if typ := c.String("type"); typ != "" {
		conf.Storage = config.StorageType(typ)
	}
	if u := c.String("url"); u != "" {
		conf.BaseURL = u
	}
	l.SetLevel(conf.LogLevel)
	db, aDb, err := Storage(conf, l)
	if err != nil {
		l.Errorf("Unable to access storage: %s", err)
		return nil, err
	}
	return New(aDb, db, conf), nil

M internal/cmd/storage_all.go => internal/cmd/storage_all.go +29 -21
@@ 35,13 35,17 @@ var (
	}
)

func getBadgerStorage(c config.Options, l logrus.FieldLogger) (st.Repository, osin.Storage, error) {
func getBadgerStorage(c config.Options, l logrus.FieldLogger) (st.Store, osin.Storage, error) {
	l.Debugf("Initializing badger storage at %s", c.Badger())
	db := badger.New(badger.Config{
	db, err := badger.New(badger.Config{
		Path:  c.Badger(),
		BaseURL: c.BaseURL,
		LogFn: InfoLogFn(l),
		ErrFn: ErrLogFn(l),
	}, c.BaseURL)
	})
	if err != nil {
		return nil, nil, err
	}
	oauth := authbadger.New(authbadger.Config{
		Path:  c.BadgerOAuth2(),
		Host:  c.Host,


@@ 51,13 55,17 @@ func getBadgerStorage(c config.Options, l logrus.FieldLogger) (st.Repository, os
	return db, oauth, nil
}

func getBoltStorage(c config.Options, l logrus.FieldLogger) (st.Repository, osin.Storage, error) {
func getBoltStorage(c config.Options, l logrus.FieldLogger) (st.Store, osin.Storage, error) {
	l.Debugf("Initializing boltdb storage at %s", c.BoltDB())
	db := boltdb.New(boltdb.Config{
	db, err := boltdb.New(boltdb.Config{
		Path:  c.BoltDB(),
		BaseURL: c.BaseURL,
		LogFn: InfoLogFn(l),
		ErrFn: ErrLogFn(l),
	}, c.BaseURL)
	})
	if err != nil {
		return nil, nil, err
	}

	oauth := authboltdb.New(authboltdb.Config{
		Path:       c.BoltDBOAuth2(),


@@ 68,39 76,39 @@ func getBoltStorage(c config.Options, l logrus.FieldLogger) (st.Repository, osin
	return db, oauth, nil
}

func getFsStorage(c config.Options, l logrus.FieldLogger) (st.Repository, osin.Storage, error) {
func getFsStorage(c config.Options, l logrus.FieldLogger) (st.Store, osin.Storage, error) {
	l.Debugf("Initializing fs storage at %s", c.BaseStoragePath())
	oauth := authfs.New(authfs.Config{
		Path:  c.BaseStoragePath(),
		LogFn: InfoLogFn(l),
		ErrFn: ErrLogFn(l),
	})
	db, err := fs.New(fs.Config{
		StoragePath: c.StoragePath,
		Env:         string(c.Env),
		BaseURL:     c.BaseURL,
	})
	if err != nil {
		return nil, oauth, err
		return nil, nil, err
	}
	oauth := authfs.New(authfs.Config{
		Path:  c.BaseStoragePath(),
		LogFn: InfoLogFn(l),
		ErrFn: ErrLogFn(l),
	})
	return db, oauth, nil
}

func getSqliteStorage(c config.Options, l logrus.FieldLogger) (st.Repository, osin.Storage, error) {
func getSqliteStorage(c config.Options, l logrus.FieldLogger) (st.Store, osin.Storage, error) {
	l.Debugf("Initializing sqlite storage at %s", c.StoragePath)
	db, err := sqlite.New(sqlite.Config{})
	if err != nil {
		return nil, nil, err
	}
	oauth := authsqlite.New(authsqlite.Config{
		Path:  c.BaseStoragePath(),
		LogFn: InfoLogFn(l),
		ErrFn: ErrLogFn(l),
	})
	db, err := sqlite.New(sqlite.Config{})
	if err != nil {
		return nil, nil, err
	}
	return db, oauth, nil

}

func getPgxStorage(c config.Options, l logrus.FieldLogger) (st.Repository, osin.Storage, error) {
func getPgxStorage(c config.Options, l logrus.FieldLogger) (st.Store, osin.Storage, error) {
	// @todo(marius): we're no longer loading SQL db config env variables
	l.Debugf("Initializing pgx storage at %s", c.StoragePath)
	conf := pgx.Config{}


@@ 122,7 130,7 @@ func getPgxStorage(c config.Options, l logrus.FieldLogger) (st.Repository, osin.
	return db, oauth, errors.NotImplementedf("sqlite storage backend is not implemented yet")
}

func Storage(c config.Options, l logrus.FieldLogger) (st.Repository, osin.Storage, error) {
func Storage(c config.Options, l logrus.FieldLogger) (st.Store, osin.Storage, error) {
	switch c.Storage {
	case config.StorageBoltDB:
		return getBoltStorage(c, l)

M ui.go => ui.go +1 -1
@@ 285,7 285,7 @@ func (m model) View() string {
type ColorPair = lipgloss.AdaptiveColor

// NewColorPair is a helper function for creating a ColorPair.
func NewColorPair(dark, light string) ColorPair {
func NewColorPair(dark, light string) lipgloss.AdaptiveColor {
	return lipgloss.AdaptiveColor{Dark: dark, Light: light}
}