diff --git a/cmd/cli/command/command.go b/cmd/cli/command/command.go index fd75e70..45b6344 100644 --- a/cmd/cli/command/command.go +++ b/cmd/cli/command/command.go @@ -31,8 +31,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) { } switch cmd { - case "sync": - return NewSync(conf) + case "fetch": + return NewFetch(conf) case "today": return NewToday(conf) case "tomorrow": diff --git a/cmd/cli/command/sync.go b/cmd/cli/command/fetch.go similarity index 57% rename from cmd/cli/command/sync.go rename to cmd/cli/command/fetch.go index 07ce15a..2edac5b 100644 --- a/cmd/cli/command/sync.go +++ b/cmd/cli/command/fetch.go @@ -10,29 +10,29 @@ import ( "git.ewintr.nl/gte/pkg/mstore" ) -type Sync struct { - syncer *process.Sync +type Fetch struct { + fetcher *process.Fetch } -func NewSync(conf *configuration.Configuration) (*Sync, error) { +func NewFetch(conf *configuration.Configuration) (*Fetch, error) { msgStore := mstore.NewIMAP(conf.IMAP()) remote := storage.NewRemoteRepository(msgStore) local, err := storage.NewSqlite(conf.Sqlite()) if err != nil { - return &Sync{}, err + return &Fetch{}, err } - syncer := process.NewSync(remote, local) + fetcher := process.NewFetch(remote, local) - return &Sync{ - syncer: syncer, + return &Fetch{ + fetcher: fetcher, }, nil } -func (s *Sync) Do() string { - result, err := s.syncer.Process() +func (s *Fetch) Do() string { + result, err := s.fetcher.Process() if err != nil { return format.FormatError(err) } - return fmt.Sprintf("synced %d tasks\n", result.Count) + return fmt.Sprintf("fetched %d tasks\n", result.Count) } diff --git a/internal/process/sync.go b/internal/process/fetch.go similarity index 58% rename from internal/process/sync.go rename to internal/process/fetch.go index 2dc593f..68ad5cc 100644 --- a/internal/process/sync.go +++ b/internal/process/fetch.go @@ -10,28 +10,28 @@ import ( ) var ( - ErrSyncProcess = errors.New("could not sync local repository") + ErrFetchProcess = errors.New("could not fetch tasks") ) -// Sync fetches all tasks in regular folders from the remote repository and overwrites what is stored locally -type Sync struct { +// Fetch fetches all tasks in regular folders from the remote repository and overwrites what is stored locally +type Fetch struct { remote *storage.RemoteRepository local storage.LocalRepository } -type SyncResult struct { +type FetchResult struct { Duration string `json:"duration"` Count int `json:"count"` } -func NewSync(remote *storage.RemoteRepository, local storage.LocalRepository) *Sync { - return &Sync{ +func NewFetch(remote *storage.RemoteRepository, local storage.LocalRepository) *Fetch { + return &Fetch{ remote: remote, local: local, } } -func (s *Sync) Process() (*SyncResult, error) { +func (s *Fetch) Process() (*FetchResult, error) { start := time.Now() tasks := []*task.Task{} @@ -41,7 +41,7 @@ func (s *Sync) Process() (*SyncResult, error) { } folderTasks, err := s.remote.FindAll(folder) if err != nil { - return &SyncResult{}, fmt.Errorf("%w: %v", ErrSyncProcess, err) + return &FetchResult{}, fmt.Errorf("%w: %v", ErrFetchProcess, err) } for _, t := range folderTasks { @@ -50,10 +50,10 @@ func (s *Sync) Process() (*SyncResult, error) { } if err := s.local.SetTasks(tasks); err != nil { - return &SyncResult{}, fmt.Errorf("%w: %v", ErrSyncProcess, err) + return &FetchResult{}, fmt.Errorf("%w: %v", ErrFetchProcess, err) } - return &SyncResult{ + return &FetchResult{ Duration: time.Since(start).String(), Count: len(tasks), }, nil diff --git a/internal/process/sync_test.go b/internal/process/fetch_test.go similarity index 94% rename from internal/process/sync_test.go rename to internal/process/fetch_test.go index c989331..2a08855 100644 --- a/internal/process/sync_test.go +++ b/internal/process/fetch_test.go @@ -11,7 +11,7 @@ import ( "git.ewintr.nl/gte/pkg/mstore" ) -func TestSyncProcess(t *testing.T) { +func TestFetchProcess(t *testing.T) { task1 := &task.Task{ Id: "id1", Version: 1, @@ -35,7 +35,7 @@ func TestSyncProcess(t *testing.T) { remote := storage.NewRemoteRepository(mstorer) local := storage.NewMemory() - syncer := process.NewSync(remote, local) + syncer := process.NewFetch(remote, local) actResult, err := syncer.Process() test.OK(t, err) test.Equals(t, 2, actResult.Count)