list project

This commit is contained in:
Erik Winter 2024-12-31 09:22:03 +01:00
parent bf8c2b1f5d
commit 2d8c7556db
5 changed files with 36 additions and 6 deletions

BIN
dist/plan vendored

Binary file not shown.

View File

@ -11,23 +11,33 @@ import (
) )
type ListArgs struct { type ListArgs struct {
fieldTPL map[string][]string
params storage.TaskListParams params storage.TaskListParams
} }
func NewListArgs() ListArgs { func NewListArgs() ListArgs {
return ListArgs{} return ListArgs{
fieldTPL: map[string][]string{
"project": {"p", "project"},
},
}
} }
func (la ListArgs) Parse(main []string, flags map[string]string) (Command, error) { func (la ListArgs) Parse(main []string, fields map[string]string) (Command, error) {
if len(main) > 2 { if len(main) > 2 {
return nil, ErrWrongCommand return nil, ErrWrongCommand
} }
fields, err := ResolveFields(fields, la.fieldTPL)
if err != nil {
return nil, err
}
now := time.Now() now := time.Now()
today := item.NewDate(now.Year(), int(now.Month()), now.Day()) today := item.NewDate(now.Year(), int(now.Month()), now.Day())
tomorrow := item.NewDate(now.Year(), int(now.Month()), now.Day()+1) tomorrow := item.NewDate(now.Year(), int(now.Month()), now.Day()+1)
var date item.Date var date item.Date
var includeBefore, recurrer bool var includeBefore, recurrer bool
var project string
switch len(main) { switch len(main) {
case 0: case 0:
@ -40,7 +50,10 @@ func (la ListArgs) Parse(main []string, flags map[string]string) (Command, error
includeBefore = true includeBefore = true
case slices.Contains([]string{"tomorrow", "tom"}, main[0]): case slices.Contains([]string{"tomorrow", "tom"}, main[0]):
date = tomorrow date = tomorrow
case main[0] == "list": case main[0] == "list" || main[0] == "l":
if val, ok := fields["project"]; ok {
project = val
}
default: default:
return nil, ErrWrongCommand return nil, ErrWrongCommand
} }
@ -60,6 +73,7 @@ func (la ListArgs) Parse(main []string, flags map[string]string) (Command, error
Date: date, Date: date,
IncludeBefore: includeBefore, IncludeBefore: includeBefore,
Recurrer: recurrer, Recurrer: recurrer,
Project: project,
}, },
}, },
}, nil }, nil

View File

@ -80,6 +80,10 @@ func (t *SqliteTask) FindMany(params storage.TaskListParams) ([]item.Task, error
where = append(where, `date <= ?`) where = append(where, `date <= ?`)
args = append(args, params.Date.String()) args = append(args, params.Date.String())
} }
if params.Project != "" {
where = append(where, `project = ?`)
args = append(args, params.Project)
}
if len(where) > 0 { if len(where) > 0 {
query += ` WHERE ` + where[0] query += ` WHERE ` + where[0]

View File

@ -32,6 +32,7 @@ type TaskListParams struct {
Recurrer bool Recurrer bool
Date item.Date Date item.Date
IncludeBefore bool IncludeBefore bool
Project string
} }
type Task interface { type Task interface {
@ -53,6 +54,9 @@ func Match(tsk item.Task, params TaskListParams) bool {
return false return false
} }
} }
if params.Project != "" && params.Project != tsk.Project {
return false
}
return true return true
} }

View File

@ -16,6 +16,7 @@ func TestMatch(t *testing.T) {
Recurrer: item.NewRecurrer("2024-12-29, daily"), Recurrer: item.NewRecurrer("2024-12-29, daily"),
TaskBody: item.TaskBody{ TaskBody: item.TaskBody{
Title: "name", Title: "name",
Project: "p1",
}, },
} }
tskNotMatch := item.Task{ tskNotMatch := item.Task{
@ -23,6 +24,7 @@ func TestMatch(t *testing.T) {
Date: item.NewDate(2024, 12, 28), Date: item.NewDate(2024, 12, 28),
TaskBody: item.TaskBody{ TaskBody: item.TaskBody{
Title: "name", Title: "name",
Project: "p2",
}, },
} }
@ -42,6 +44,12 @@ func TestMatch(t *testing.T) {
Recurrer: true, Recurrer: true,
}, },
}, },
{
name: "project",
params: storage.TaskListParams{
Project: "p1",
},
},
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
if !storage.Match(tskMatch, tc.params) { if !storage.Match(tskMatch, tc.params) {