diff --git a/cmd/cli/command/command.go b/cmd/cli/command/command.go index a0bd1fa..9fad960 100644 --- a/cmd/cli/command/command.go +++ b/cmd/cli/command/command.go @@ -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() +} diff --git a/cmd/cli/command/command_test.go b/cmd/cli/command/command_test.go index 1ec94a2..f0345ec 100644 --- a/cmd/cli/command/command_test.go +++ b/cmd/cli/command/command_test.go @@ -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"}, diff --git a/cmd/cli/command/show.go b/cmd/cli/command/show.go new file mode 100644 index 0000000..c9e8038 --- /dev/null +++ b/cmd/cli/command/show.go @@ -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) +} diff --git a/cmd/cli/format/format.go b/cmd/cli/format/format.go index 762eb2f..064bf80 100644 --- a/cmd/cli/format/format.go +++ b/cmd/cli/format/format.go @@ -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 +}