removed unused command functions

This commit is contained in:
Erik Winter 2021-08-20 10:08:15 +02:00
parent c035bf5cab
commit 928270059a
14 changed files with 5 additions and 148 deletions

View File

@ -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()))

View File

@ -14,7 +14,6 @@ var (
type Command interface {
Do() string
Cmd() string
}
func Parse(args []string, conf *configuration.Configuration) (Command, error) {

View File

@ -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())
})
}
}

View File

@ -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 {

View File

@ -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"
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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)

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {