simple show task

This commit is contained in:
Erik Winter 2021-07-27 07:10:01 +02:00
parent f20b151e12
commit c44a537e70
4 changed files with 67 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package command
import ( import (
"errors" "errors"
"strconv"
"git.ewintr.nl/gte/internal/configuration" "git.ewintr.nl/gte/internal/configuration"
) )
@ -21,6 +22,12 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
} }
cmd, cmdArgs := args[0], args[1:] cmd, cmdArgs := args[0], args[1:]
id, err := strconv.Atoi(cmd)
if err == nil {
return parseTaskCommand(id, cmdArgs, conf)
}
switch cmd { switch cmd {
case "sync": case "sync":
return NewSync(conf) return NewSync(conf)
@ -36,3 +43,11 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
return NewEmpty() return NewEmpty()
} }
} }
func parseTaskCommand(id int, tArgs []string, conf *configuration.Configuration) (Command, error) {
if len(tArgs) == 0 {
return NewShow(id, conf)
}
return NewEmpty()
}

View File

@ -33,6 +33,11 @@ func TestCommand(t *testing.T) {
args: []string{"tomorrow"}, args: []string{"tomorrow"},
exp: "tomorrow", exp: "tomorrow",
}, },
{
name: "show task",
args: []string{"123"},
exp: "show",
},
{ {
name: "done", name: "done",
args: []string{"done"}, args: []string{"done"},

35
cmd/cli/command/show.go Normal file
View File

@ -0,0 +1,35 @@
package command
import (
"git.ewintr.nl/gte/cmd/cli/format"
"git.ewintr.nl/gte/internal/configuration"
"git.ewintr.nl/gte/internal/storage"
)
type Show struct {
local storage.LocalRepository
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 {
return &Show{}, err
}
return &Show{
local: local,
id: id,
}, nil
}
func (s *Show) Do() string {
t, err := s.local.FindByLocalId(s.id)
if err != nil {
return format.FormatError(err)
}
return format.FormatTask(s.id, t)
}

View File

@ -28,3 +28,15 @@ func FormatTaskTable(local storage.LocalRepository, tasks []*task.Task) string {
return output return output
} }
func FormatTask(id int, t *task.Task) string {
output := fmt.Sprintf(`action: %s
project: %s
due: %s
`, t.Action, t.Project, t.Due.String())
if t.IsRecurrer() {
output += fmt.Sprintf("recur:%s", t.Recur.String())
}
return output
}