gte/cmd/cli/command/sync.go

39 lines
776 B
Go
Raw Normal View History

2021-07-09 09:42:44 +02:00
package command
import (
"fmt"
2021-07-10 11:44:06 +02:00
"git.ewintr.nl/gte/cmd/cli/format"
2021-07-09 09:42:44 +02:00
"git.ewintr.nl/gte/internal/configuration"
"git.ewintr.nl/gte/internal/process"
"git.ewintr.nl/gte/internal/storage"
"git.ewintr.nl/gte/pkg/mstore"
)
type Sync struct {
syncer *process.Sync
}
func NewSync(conf *configuration.Configuration) (*Sync, error) {
msgStore := mstore.NewIMAP(conf.IMAP())
remote := storage.NewRemoteRepository(msgStore)
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Sync{}, err
}
syncer := process.NewSync(remote, local)
return &Sync{
syncer: syncer,
}, nil
}
func (s *Sync) Do() string {
result, err := s.syncer.Process()
if err != nil {
2021-07-10 11:44:06 +02:00
return format.FormatError(err)
2021-07-09 09:42:44 +02:00
}
return fmt.Sprintf("synced %d tasks\n", result.Count)
}