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

View File

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

View File

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

View File

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