2021-07-10 11:44:06 +02:00
|
|
|
package format
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-07-14 07:17:53 +02:00
|
|
|
"git.ewintr.nl/gte/internal/storage"
|
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())
|
|
|
|
}
|
|
|
|
|
2021-07-14 07:17:53 +02:00
|
|
|
func FormatTaskTable(local storage.LocalRepository, tasks []*task.Task) string {
|
|
|
|
if len(tasks) == 0 {
|
|
|
|
return "no tasks to display\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
localIds, err := local.LocalIds()
|
|
|
|
if err != nil {
|
|
|
|
return FormatError(err)
|
|
|
|
}
|
|
|
|
|
2021-07-10 11:44:06 +02:00
|
|
|
var output string
|
|
|
|
for _, t := range tasks {
|
2021-07-14 07:17:53 +02:00
|
|
|
output += fmt.Sprintf("%d\t%s\t%s\n", localIds[t.Id], t.Due.String(), t.Action)
|
2021-07-10 11:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
2021-07-27 07:10:01 +02:00
|
|
|
|
|
|
|
func FormatTask(id int, t *task.Task) 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
|
|
|
|
}
|