From 928270059aabe671f1192211bc313b3cca36e09e Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Fri, 20 Aug 2021 10:08:15 +0200 Subject: [PATCH] removed unused command functions --- cmd/cli/command/add.go | 2 - cmd/cli/command/command.go | 1 - cmd/cli/command/command_test.go | 52 ----------------------- cmd/cli/command/done.go | 2 - cmd/cli/command/empty.go | 2 - cmd/cli/command/folder.go | 7 +++- cmd/cli/command/list.go | 73 --------------------------------- cmd/cli/command/project.go | 2 - cmd/cli/command/projects.go | 2 - cmd/cli/command/show.go | 2 - cmd/cli/command/sync.go | 2 - cmd/cli/command/today.go | 2 - cmd/cli/command/tomorrow.go | 2 - cmd/cli/command/update.go | 2 - 14 files changed, 5 insertions(+), 148 deletions(-) delete mode 100644 cmd/cli/command/command_test.go delete mode 100644 cmd/cli/command/list.go diff --git a/cmd/cli/command/add.go b/cmd/cli/command/add.go index a196ba9..c7d5b53 100644 --- a/cmd/cli/command/add.go +++ b/cmd/cli/command/add.go @@ -16,8 +16,6 @@ type Add struct { action string } -func (n *Add) Cmd() string { return "new" } - func NewAdd(conf *configuration.Configuration, cmdArgs []string) (*Add, error) { disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP())) diff --git a/cmd/cli/command/command.go b/cmd/cli/command/command.go index 7bf1f84..c905531 100644 --- a/cmd/cli/command/command.go +++ b/cmd/cli/command/command.go @@ -14,7 +14,6 @@ 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 deleted file mode 100644 index f1cd572..0000000 --- a/cmd/cli/command/command_test.go +++ /dev/null @@ -1,52 +0,0 @@ -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: "show task", - args: []string{"123"}, - exp: "show", - }, - { - name: "done", - args: []string{"123", "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 8fe77ba..e15f9f9 100644 --- a/cmd/cli/command/done.go +++ b/cmd/cli/command/done.go @@ -13,8 +13,6 @@ type Done struct { doner *process.Update } -func (d *Done) Cmd() string { return "done" } - func NewDone(localId int, conf *configuration.Configuration) (*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 c567704..ec28fe8 100644 --- a/cmd/cli/command/empty.go +++ b/cmd/cli/command/empty.go @@ -6,8 +6,6 @@ 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/folder.go b/cmd/cli/command/folder.go index 389390b..579625b 100644 --- a/cmd/cli/command/folder.go +++ b/cmd/cli/command/folder.go @@ -1,6 +1,7 @@ package command import ( + "errors" "strings" "git.ewintr.nl/gte/cmd/cli/format" @@ -10,12 +11,14 @@ import ( "git.ewintr.nl/gte/internal/task" ) +var ( + ErrUnknownFolder = errors.New("unknown folder") +) + type Folder struct { lister *process.List } -func (f *Folder) Cmd() string { return "folder" } - func NewFolder(conf *configuration.Configuration, cmdArgs []string) (*Folder, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil { diff --git a/cmd/cli/command/list.go b/cmd/cli/command/list.go deleted file mode 100644 index 2fada63..0000000 --- a/cmd/cli/command/list.go +++ /dev/null @@ -1,73 +0,0 @@ -package command - -import ( - "errors" - "strings" - - "git.ewintr.nl/gte/cmd/cli/format" - "git.ewintr.nl/gte/internal/configuration" - "git.ewintr.nl/gte/internal/process" - "git.ewintr.nl/gte/internal/storage" - "git.ewintr.nl/gte/internal/task" -) - -var ( - ErrUnknownFolder = errors.New("unknown folder") -) - -// List lists all the tasks in a project or a folder -type List struct { - lister *process.List -} - -func (l *List) Cmd() string { return "list" } - -func NewList(conf *configuration.Configuration, cmdArgs []string) (*List, error) { - local, err := storage.NewSqlite(conf.Sqlite()) - if err != nil { - return &List{}, err - } - if len(cmdArgs) < 2 { - return &List{}, ErrInvalidAmountOfArgs - } - - reqs, err := parseReqs(cmdArgs[0], cmdArgs[1]) - if err != nil { - return &List{}, err - } - lister := process.NewList(local, reqs) - - return &List{ - lister: lister, - }, nil -} - -func (l *List) Do() string { - res, err := l.lister.Process() - if err != nil { - return format.FormatError(err) - } - - return format.FormatTaskTable(res.Tasks) -} - -func parseReqs(kind, item string) (process.ListReqs, error) { - item = strings.ToLower(item) - switch kind { - case "folder": - for _, folder := range task.KnownFolders { - if item == strings.ToLower(folder) { - return process.ListReqs{ - Folder: folder, - }, nil - } - } - return process.ListReqs{}, ErrUnknownFolder - case "project": - return process.ListReqs{ - Project: item, - }, nil - } - - return process.ListReqs{}, process.ErrInvalidReqs -} diff --git a/cmd/cli/command/project.go b/cmd/cli/command/project.go index 5727857..1017f17 100644 --- a/cmd/cli/command/project.go +++ b/cmd/cli/command/project.go @@ -13,8 +13,6 @@ type Project struct { lister *process.List } -func (p *Project) Cmd() string { return "project" } - func NewProject(conf *configuration.Configuration, cmdArgs []string) (*Project, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil { diff --git a/cmd/cli/command/projects.go b/cmd/cli/command/projects.go index a04b404..d56cc2f 100644 --- a/cmd/cli/command/projects.go +++ b/cmd/cli/command/projects.go @@ -14,8 +14,6 @@ type Projects struct { projecter *process.Projects } -func (p *Projects) Cmd() string { return "projects" } - func NewProjects(conf *configuration.Configuration) (*Projects, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil { diff --git a/cmd/cli/command/show.go b/cmd/cli/command/show.go index 55d5a6b..c956fa2 100644 --- a/cmd/cli/command/show.go +++ b/cmd/cli/command/show.go @@ -11,8 +11,6 @@ type Show struct { id int } -func (s *Show) Cmd() string { return "show" } - func NewShow(id int, conf *configuration.Configuration) (*Show, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil { diff --git a/cmd/cli/command/sync.go b/cmd/cli/command/sync.go index 903d418..07ce15a 100644 --- a/cmd/cli/command/sync.go +++ b/cmd/cli/command/sync.go @@ -14,8 +14,6 @@ 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 5316726..5847039 100644 --- a/cmd/cli/command/today.go +++ b/cmd/cli/command/today.go @@ -13,8 +13,6 @@ type Today struct { lister *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 8725532..b5673c1 100644 --- a/cmd/cli/command/tomorrow.go +++ b/cmd/cli/command/tomorrow.go @@ -13,8 +13,6 @@ type Tomorrow struct { lister *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 { diff --git a/cmd/cli/command/update.go b/cmd/cli/command/update.go index 2114208..374a909 100644 --- a/cmd/cli/command/update.go +++ b/cmd/cli/command/update.go @@ -21,8 +21,6 @@ type Update struct { updater *process.Update } -func (u *Update) Cmd() string { return "update" } - func NewUpdate(localId int, conf *configuration.Configuration, cmdArgs []string) (*Update, error) { local, err := storage.NewSqlite(conf.Sqlite()) if err != nil {