planner/plan/command/list.go

44 lines
834 B
Go
Raw Normal View History

2024-09-30 07:34:40 +02:00
package command
import (
"fmt"
)
2024-12-27 11:20:32 +01:00
type ListArgs struct {
2024-09-30 07:34:40 +02:00
}
2024-12-27 11:20:32 +01:00
func NewListArgs() ListArgs {
return ListArgs{}
2024-09-30 07:34:40 +02:00
}
2024-12-27 11:20:32 +01:00
func (la ListArgs) Parse(main []string, flags map[string]string) (Command, error) {
2024-10-29 07:22:04 +01:00
if len(main) > 0 && main[0] != "list" {
2024-12-27 11:20:32 +01:00
return nil, ErrWrongCommand
2024-10-29 07:22:04 +01:00
}
2024-12-27 11:20:32 +01:00
return &List{}, nil
}
type List struct {
2024-10-29 07:22:04 +01:00
}
2024-12-29 10:16:03 +01:00
func (list *List) Do(deps Dependencies) ([][]string, error) {
2024-12-27 11:20:32 +01:00
localIDs, err := deps.LocalIDRepo.FindAll()
2024-10-03 07:32:48 +02:00
if err != nil {
2024-12-29 10:16:03 +01:00
return nil, fmt.Errorf("could not get local ids: %v", err)
2024-10-03 07:32:48 +02:00
}
2024-12-27 11:20:32 +01:00
all, err := deps.TaskRepo.FindAll()
2024-10-03 07:32:48 +02:00
if err != nil {
2024-12-29 10:16:03 +01:00
return nil, err
2024-10-03 07:32:48 +02:00
}
for _, e := range all {
lid, ok := localIDs[e.ID]
if !ok {
2024-12-29 10:16:03 +01:00
return nil, fmt.Errorf("could not find local id for %s", e.ID)
2024-09-30 07:34:40 +02:00
}
2024-12-19 12:06:03 +01:00
fmt.Printf("%s\t%d\t%s\t%s\t%s\n", e.ID, lid, e.Title, e.Date.String(), e.Duration.String())
2024-09-30 07:34:40 +02:00
}
2024-12-29 10:16:03 +01:00
return nil, nil
2024-09-30 07:34:40 +02:00
}