From f20b151e12fc0649c55e642ccda2007513b04f03 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Mon, 26 Jul 2021 06:59:31 +0200 Subject: [PATCH] started refactor commands --- cmd/cli/command/command.go | 1 + cmd/cli/command/command_test.go | 47 +++++++++++++++++++++++++++++++++ cmd/cli/command/done.go | 2 ++ cmd/cli/command/empty.go | 2 ++ cmd/cli/command/new.go | 2 ++ cmd/cli/command/sync.go | 2 ++ cmd/cli/command/today.go | 2 ++ cmd/cli/command/tomorrow.go | 2 ++ 8 files changed, 60 insertions(+) create mode 100644 cmd/cli/command/command_test.go diff --git a/cmd/cli/command/command.go b/cmd/cli/command/command.go index c4aa38d..a0bd1fa 100644 --- a/cmd/cli/command/command.go +++ b/cmd/cli/command/command.go @@ -12,6 +12,7 @@ var ( type Command interface { Do() string + Cmd() string } func Parse(args []string, conf *configuration.Configuration) (Command, error) { diff --git a/cmd/cli/command/command_test.go b/cmd/cli/command/command_test.go new file mode 100644 index 0000000..1ec94a2 --- /dev/null +++ b/cmd/cli/command/command_test.go @@ -0,0 +1,47 @@ +package command_test + +import ( + "testing" + + "git.ewintr.nl/go-kit/test" + "git.ewintr.nl/gte/cmd/cli/command" + "git.ewintr.nl/gte/internal/configuration" +) + +func TestCommand(t *testing.T) { + for _, tc := range []struct { + name string + args []string + exp string + }{ + { + name: "empty", + exp: "empty", + }, + { + name: "sync", + args: []string{"sync"}, + exp: "sync", + }, + { + name: "today", + args: []string{"today"}, + exp: "today", + }, + { + name: "tomorrow", + args: []string{"tomorrow"}, + exp: "tomorrow", + }, + { + name: "done", + args: []string{"done"}, + exp: "done", + }, + } { + t.Run(tc.name, func(t *testing.T) { + cmd, _ := command.Parse(tc.args, &configuration.Configuration{}) + test.Equals(t, tc.exp, cmd.Cmd()) + }) + } +} diff --git a/cmd/cli/command/done.go b/cmd/cli/command/done.go index 6bccf19..986328c 100644 --- a/cmd/cli/command/done.go +++ b/cmd/cli/command/done.go @@ -15,6 +15,8 @@ type Done struct { doner *process.Update } +func (d *Done) Cmd() string { return "done" } + func NewDone(conf *configuration.Configuration, cmdArgs []string) (*Done, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil { diff --git a/cmd/cli/command/empty.go b/cmd/cli/command/empty.go index ec28fe8..c567704 100644 --- a/cmd/cli/command/empty.go +++ b/cmd/cli/command/empty.go @@ -6,6 +6,8 @@ func NewEmpty() (*Empty, error) { return &Empty{}, nil } +func (e *Empty) Cmd() string { return "empty" } + func (cmd *Empty) Do() string { return "did nothing\n" } diff --git a/cmd/cli/command/new.go b/cmd/cli/command/new.go index 4386693..62cef85 100644 --- a/cmd/cli/command/new.go +++ b/cmd/cli/command/new.go @@ -14,6 +14,8 @@ type New struct { action string } +func (n *New) Cmd() string { return "new" } + func NewNew(conf *configuration.Configuration, cmdArgs []string) (*New, error) { if len(cmdArgs) != 1 { return &New{}, ErrInvalidAmountOfArgs diff --git a/cmd/cli/command/sync.go b/cmd/cli/command/sync.go index 07ce15a..903d418 100644 --- a/cmd/cli/command/sync.go +++ b/cmd/cli/command/sync.go @@ -14,6 +14,8 @@ type Sync struct { syncer *process.Sync } +func (s *Sync) Cmd() string { return "sync" } + func NewSync(conf *configuration.Configuration) (*Sync, error) { msgStore := mstore.NewIMAP(conf.IMAP()) remote := storage.NewRemoteRepository(msgStore) diff --git a/cmd/cli/command/today.go b/cmd/cli/command/today.go index a1f81f1..9763c02 100644 --- a/cmd/cli/command/today.go +++ b/cmd/cli/command/today.go @@ -14,6 +14,8 @@ type Today struct { todayer *process.List } +func (t *Today) Cmd() string { return "today" } + func NewToday(conf *configuration.Configuration) (*Today, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil { diff --git a/cmd/cli/command/tomorrow.go b/cmd/cli/command/tomorrow.go index 13a9e4b..d68f545 100644 --- a/cmd/cli/command/tomorrow.go +++ b/cmd/cli/command/tomorrow.go @@ -14,6 +14,8 @@ type Tomorrow struct { tomorrower *process.List } +func (t *Tomorrow) Cmd() string { return "tomorrow" } + func NewTomorrow(conf *configuration.Configuration) (*Tomorrow, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil {