diff --git a/cmd/cli/command/command.go b/cmd/cli/command/command.go index 7216114..9cef918 100644 --- a/cmd/cli/command/command.go +++ b/cmd/cli/command/command.go @@ -2,7 +2,6 @@ package command import ( "errors" - "fmt" "git.ewintr.nl/gte/internal/configuration" ) @@ -34,7 +33,3 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) { return NewEmpty() } } - -func FormatError(err error) string { - return fmt.Sprintf("could not perform command.\n\nerror: %s\n", err.Error()) -} diff --git a/cmd/cli/command/new.go b/cmd/cli/command/new.go index 90111ad..4386693 100644 --- a/cmd/cli/command/new.go +++ b/cmd/cli/command/new.go @@ -1,6 +1,7 @@ package command import ( + "git.ewintr.nl/gte/cmd/cli/format" "git.ewintr.nl/gte/internal/configuration" "git.ewintr.nl/gte/internal/storage" "git.ewintr.nl/gte/internal/task" @@ -28,7 +29,7 @@ func NewNew(conf *configuration.Configuration, cmdArgs []string) (*New, error) { func (n *New) Do() string { if err := n.disp.Dispatch(&task.Task{Action: n.action}); err != nil { - return FormatError(err) + return format.FormatError(err) } return "message sent\n" diff --git a/cmd/cli/command/sync.go b/cmd/cli/command/sync.go index 9bbb076..07ce15a 100644 --- a/cmd/cli/command/sync.go +++ b/cmd/cli/command/sync.go @@ -3,6 +3,7 @@ package command import ( "fmt" + "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" @@ -30,7 +31,7 @@ func NewSync(conf *configuration.Configuration) (*Sync, error) { func (s *Sync) Do() string { result, err := s.syncer.Process() if err != nil { - return FormatError(err) + return format.FormatError(err) } return fmt.Sprintf("synced %d tasks\n", result.Count) diff --git a/cmd/cli/command/today.go b/cmd/cli/command/today.go index 3f5aba2..e2cd742 100644 --- a/cmd/cli/command/today.go +++ b/cmd/cli/command/today.go @@ -1,8 +1,7 @@ package command import ( - "fmt" - + "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" @@ -33,16 +32,11 @@ func NewToday(conf *configuration.Configuration) (*Today, error) { func (t *Today) Do() string { res, err := t.todayer.Process() if err != nil { - return FormatError(err) + return format.FormatError(err) } if len(res.Tasks) == 0 { return "nothing left\n" } - var msg string - for _, t := range res.Tasks { - msg += fmt.Sprintf("%s - %s\n", t.Project, t.Action) - } - - return msg + return format.FormatTaskTable(res.Tasks) } diff --git a/cmd/cli/command/tomorrow.go b/cmd/cli/command/tomorrow.go index 49d4251..d132274 100644 --- a/cmd/cli/command/tomorrow.go +++ b/cmd/cli/command/tomorrow.go @@ -1,8 +1,7 @@ package command import ( - "fmt" - + "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" @@ -33,17 +32,12 @@ func NewTomorrow(conf *configuration.Configuration) (*Tomorrow, error) { func (t *Tomorrow) Do() string { res, err := t.tomorrower.Process() if err != nil { - return FormatError(err) + return format.FormatError(err) } if len(res.Tasks) == 0 { return "nothing to do tomorrow\n" } - var msg string - for _, t := range res.Tasks { - msg += fmt.Sprintf("%s - %s", t.Project, t.Action) - } - - return msg + return format.FormatTaskTable(res.Tasks) } diff --git a/cmd/cli/format/format.go b/cmd/cli/format/format.go new file mode 100644 index 0000000..32a7d29 --- /dev/null +++ b/cmd/cli/format/format.go @@ -0,0 +1,20 @@ +package format + +import ( + "fmt" + + "git.ewintr.nl/gte/internal/task" +) + +func FormatError(err error) string { + return fmt.Sprintf("could not perform command.\n\nerror: %s\n", err.Error()) +} + +func FormatTaskTable(tasks []*task.Task) string { + var output string + for _, t := range tasks { + output += fmt.Sprintf("%s\t%s\t%s\n", t.Id, t.Due.String(), t.Action) + } + + return output +}