started refactor commands

This commit is contained in:
Erik Winter 2021-07-26 06:59:31 +02:00
parent 1c25c8182c
commit f20b151e12
8 changed files with 60 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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