started refactor commands
This commit is contained in:
parent
1c25c8182c
commit
f20b151e12
|
@ -12,6 +12,7 @@ var (
|
||||||
|
|
||||||
type Command interface {
|
type Command interface {
|
||||||
Do() string
|
Do() string
|
||||||
|
Cmd() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
||||||
|
|
|
@ -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())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,8 @@ type Done struct {
|
||||||
doner *process.Update
|
doner *process.Update
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Done) Cmd() string { return "done" }
|
||||||
|
|
||||||
func NewDone(conf *configuration.Configuration, cmdArgs []string) (*Done, error) {
|
func NewDone(conf *configuration.Configuration, cmdArgs []string) (*Done, error) {
|
||||||
local, err := storage.NewSqlite(conf.Sqlite())
|
local, err := storage.NewSqlite(conf.Sqlite())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,6 +6,8 @@ func NewEmpty() (*Empty, error) {
|
||||||
return &Empty{}, nil
|
return &Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Empty) Cmd() string { return "empty" }
|
||||||
|
|
||||||
func (cmd *Empty) Do() string {
|
func (cmd *Empty) Do() string {
|
||||||
return "did nothing\n"
|
return "did nothing\n"
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ type New struct {
|
||||||
action string
|
action string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *New) Cmd() string { return "new" }
|
||||||
|
|
||||||
func NewNew(conf *configuration.Configuration, cmdArgs []string) (*New, error) {
|
func NewNew(conf *configuration.Configuration, cmdArgs []string) (*New, error) {
|
||||||
if len(cmdArgs) != 1 {
|
if len(cmdArgs) != 1 {
|
||||||
return &New{}, ErrInvalidAmountOfArgs
|
return &New{}, ErrInvalidAmountOfArgs
|
||||||
|
|
|
@ -14,6 +14,8 @@ type Sync struct {
|
||||||
syncer *process.Sync
|
syncer *process.Sync
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Sync) Cmd() string { return "sync" }
|
||||||
|
|
||||||
func NewSync(conf *configuration.Configuration) (*Sync, error) {
|
func NewSync(conf *configuration.Configuration) (*Sync, error) {
|
||||||
msgStore := mstore.NewIMAP(conf.IMAP())
|
msgStore := mstore.NewIMAP(conf.IMAP())
|
||||||
remote := storage.NewRemoteRepository(msgStore)
|
remote := storage.NewRemoteRepository(msgStore)
|
||||||
|
|
|
@ -14,6 +14,8 @@ type Today struct {
|
||||||
todayer *process.List
|
todayer *process.List
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Today) Cmd() string { return "today" }
|
||||||
|
|
||||||
func NewToday(conf *configuration.Configuration) (*Today, error) {
|
func NewToday(conf *configuration.Configuration) (*Today, error) {
|
||||||
local, err := storage.NewSqlite(conf.Sqlite())
|
local, err := storage.NewSqlite(conf.Sqlite())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -14,6 +14,8 @@ type Tomorrow struct {
|
||||||
tomorrower *process.List
|
tomorrower *process.List
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tomorrow) Cmd() string { return "tomorrow" }
|
||||||
|
|
||||||
func NewTomorrow(conf *configuration.Configuration) (*Tomorrow, error) {
|
func NewTomorrow(conf *configuration.Configuration) (*Tomorrow, error) {
|
||||||
local, err := storage.NewSqlite(conf.Sqlite())
|
local, err := storage.NewSqlite(conf.Sqlite())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue