gte/cmd/cli/command/fetch.go

39 lines
772 B
Go
Raw Normal View History

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