gte/cmd/cli/format/format.go

45 lines
872 B
Go
Raw Normal View History

2021-07-10 11:44:06 +02:00
package format
import (
"fmt"
2021-08-20 11:27:12 +02:00
"sort"
2021-07-10 11:44:06 +02:00
"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.LocalTask) string {
2021-07-14 07:17:53 +02:00
if len(tasks) == 0 {
return "no tasks to display\n"
}
2021-08-20 17:50:08 +02:00
sort.Sort(task.ByDefault(tasks))
2021-08-20 11:27:12 +02:00
2021-07-10 11:44:06 +02:00
var output string
for _, t := range tasks {
var updateStr string
2021-09-01 06:52:21 +02:00
if t.LocalStatus == task.STATUS_UPDATED {
updateStr = " *"
}
output += fmt.Sprintf("%d%s\t%s\t%s (%s)\n", t.LocalId, updateStr, t.Due.String(), t.Action, t.Project)
2021-07-10 11:44:06 +02:00
}
return output
}
2021-07-27 07:10:01 +02:00
func FormatTask(t *task.LocalTask) string {
2021-08-16 07:09:06 +02:00
output := fmt.Sprintf(`folder: %s
action: %s
2021-07-27 07:10:01 +02:00
project: %s
due: %s
2021-08-16 07:09:06 +02:00
`, t.Folder, t.Action, t.Project, t.Due.String())
2021-07-27 07:10:01 +02:00
if t.IsRecurrer() {
output += fmt.Sprintf("recur:%s", t.Recur.String())
}
return output
}