simple show task
This commit is contained in:
parent
f20b151e12
commit
c44a537e70
|
@ -2,6 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"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:]
|
||||
|
||||
id, err := strconv.Atoi(cmd)
|
||||
if err == nil {
|
||||
return parseTaskCommand(id, cmdArgs, conf)
|
||||
}
|
||||
|
||||
switch cmd {
|
||||
case "sync":
|
||||
return NewSync(conf)
|
||||
|
@ -36,3 +43,11 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
|||
return NewEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
func parseTaskCommand(id int, tArgs []string, conf *configuration.Configuration) (Command, error) {
|
||||
if len(tArgs) == 0 {
|
||||
return NewShow(id, conf)
|
||||
}
|
||||
|
||||
return NewEmpty()
|
||||
}
|
||||
|
|
|
@ -33,6 +33,11 @@ func TestCommand(t *testing.T) {
|
|||
args: []string{"tomorrow"},
|
||||
exp: "tomorrow",
|
||||
},
|
||||
{
|
||||
name: "show task",
|
||||
args: []string{"123"},
|
||||
exp: "show",
|
||||
},
|
||||
{
|
||||
name: "done",
|
||||
args: []string{"done"},
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -28,3 +28,15 @@ func FormatTaskTable(local storage.LocalRepository, tasks []*task.Task) string {
|
|||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue