Compare commits
No commits in common. "a9d5da283d279348b5eb12e2d67cb8708f2a5808" and "656988c052716d989405474d51077607fed79afb" have entirely different histories.
a9d5da283d
...
656988c052
Binary file not shown.
|
@ -82,16 +82,10 @@ func FindFields(args []string) ([]string, map[string]string) {
|
||||||
fields := make(map[string]string)
|
fields := make(map[string]string)
|
||||||
main := make([]string, 0)
|
main := make([]string, 0)
|
||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
// normal key:value
|
|
||||||
if k, v, ok := strings.Cut(args[i], ":"); ok && !strings.Contains(k, " ") {
|
if k, v, ok := strings.Cut(args[i], ":"); ok && !strings.Contains(k, " ") {
|
||||||
fields[k] = v
|
fields[k] = v
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// empty key:
|
|
||||||
if !strings.Contains(args[i], " ") && strings.HasSuffix(args[i], ":") {
|
|
||||||
k := strings.TrimSuffix(args[i], ":")
|
|
||||||
fields[k] = ""
|
|
||||||
}
|
|
||||||
main = append(main, args[i])
|
main = append(main, args[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ func NewListArgs() ListArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (la ListArgs) Parse(main []string, fields map[string]string) (Command, error) {
|
func (la ListArgs) Parse(main []string, fields map[string]string) (Command, error) {
|
||||||
if len(main) > 1 {
|
if len(main) > 2 {
|
||||||
return nil, ErrWrongCommand
|
return nil, ErrWrongCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ func (la ListArgs) Parse(main []string, fields map[string]string) (Command, erro
|
||||||
fields["to"] = today.Add(7).String()
|
fields["to"] = today.Add(7).String()
|
||||||
case main[0] == "recur":
|
case main[0] == "recur":
|
||||||
fields["recurring"] = "true"
|
fields["recurring"] = "true"
|
||||||
// case main[0] == "list":
|
case main[0] == "list":
|
||||||
// fields["from"] = today.String()
|
fields["from"] = today.String()
|
||||||
// fields["to"] = today.String()
|
fields["to"] = today.String()
|
||||||
default:
|
default:
|
||||||
return nil, ErrWrongCommand
|
return nil, ErrWrongCommand
|
||||||
}
|
}
|
||||||
|
@ -136,46 +136,15 @@ type ListResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr ListResult) Render() string {
|
func (lr ListResult) Render() string {
|
||||||
var showRec, showDur bool
|
data := [][]string{{"id", "project", "date", "dur", "title"}}
|
||||||
for _, tl := range lr.Tasks {
|
for _, tl := range lr.Tasks {
|
||||||
if tl.Task.Recurrer != nil {
|
data = append(data, []string{
|
||||||
showRec = true
|
fmt.Sprintf("%d", tl.LocalID),
|
||||||
}
|
tl.Task.Project,
|
||||||
if tl.Task.Duration > time.Duration(0) {
|
tl.Task.Date.String(),
|
||||||
showDur = true
|
tl.Task.Duration.String(),
|
||||||
}
|
tl.Task.Title,
|
||||||
}
|
})
|
||||||
|
|
||||||
title := []string{"id"}
|
|
||||||
if showRec {
|
|
||||||
title = append(title, "rec")
|
|
||||||
}
|
|
||||||
title = append(title, "project", "date")
|
|
||||||
if showDur {
|
|
||||||
title = append(title, "dur")
|
|
||||||
}
|
|
||||||
title = append(title, "title")
|
|
||||||
|
|
||||||
data := [][]string{title}
|
|
||||||
for _, tl := range lr.Tasks {
|
|
||||||
row := []string{fmt.Sprintf("%d", tl.LocalID)}
|
|
||||||
if showRec {
|
|
||||||
recStr := ""
|
|
||||||
if tl.Task.Recurrer != nil {
|
|
||||||
recStr = "*"
|
|
||||||
}
|
|
||||||
row = append(row, recStr)
|
|
||||||
}
|
|
||||||
row = append(row, tl.Task.Project, tl.Task.Date.String())
|
|
||||||
if showDur {
|
|
||||||
durStr := ""
|
|
||||||
if tl.Task.Duration > time.Duration(0) {
|
|
||||||
durStr = tl.Task.Duration.String()
|
|
||||||
}
|
|
||||||
row = append(row, durStr)
|
|
||||||
}
|
|
||||||
row = append(row, tl.Task.Title)
|
|
||||||
data = append(data, row)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("\n%s\n", format.Table(data))
|
return fmt.Sprintf("\n%s\n", format.Table(data))
|
||||||
|
|
|
@ -3,7 +3,6 @@ package command
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -14,7 +13,6 @@ import (
|
||||||
|
|
||||||
type UpdateArgs struct {
|
type UpdateArgs struct {
|
||||||
fieldTPL map[string][]string
|
fieldTPL map[string][]string
|
||||||
NeedUpdate []string
|
|
||||||
LocalID int
|
LocalID int
|
||||||
Title string
|
Title string
|
||||||
Project string
|
Project string
|
||||||
|
@ -49,55 +47,41 @@ func (ua UpdateArgs) Parse(main []string, fields map[string]string) (Command, er
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
args := UpdateArgs{
|
args := UpdateArgs{
|
||||||
NeedUpdate: make([]string, 0),
|
|
||||||
LocalID: localID,
|
LocalID: localID,
|
||||||
Title: strings.Join(main[2:], " "),
|
Title: strings.Join(main[2:], " "),
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := fields["project"]; ok {
|
if val, ok := fields["project"]; ok {
|
||||||
args.NeedUpdate = append(args.NeedUpdate, "project")
|
|
||||||
args.Project = val
|
args.Project = val
|
||||||
}
|
}
|
||||||
if val, ok := fields["date"]; ok {
|
if val, ok := fields["date"]; ok {
|
||||||
args.NeedUpdate = append(args.NeedUpdate, "date")
|
|
||||||
if val != "" {
|
|
||||||
d := item.NewDateFromString(val)
|
d := item.NewDateFromString(val)
|
||||||
if d.IsZero() {
|
if d.IsZero() {
|
||||||
return nil, fmt.Errorf("%w: could not parse date", ErrInvalidArg)
|
return nil, fmt.Errorf("%w: could not parse date", ErrInvalidArg)
|
||||||
}
|
}
|
||||||
args.Date = d
|
args.Date = d
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if val, ok := fields["time"]; ok {
|
if val, ok := fields["time"]; ok {
|
||||||
args.NeedUpdate = append(args.NeedUpdate, "time")
|
|
||||||
if val != "" {
|
|
||||||
t := item.NewTimeFromString(val)
|
t := item.NewTimeFromString(val)
|
||||||
if t.IsZero() {
|
if t.IsZero() {
|
||||||
return nil, fmt.Errorf("%w: could not parse time", ErrInvalidArg)
|
return nil, fmt.Errorf("%w: could not parse time", ErrInvalidArg)
|
||||||
}
|
}
|
||||||
args.Time = t
|
args.Time = t
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if val, ok := fields["duration"]; ok {
|
if val, ok := fields["duration"]; ok {
|
||||||
args.NeedUpdate = append(args.NeedUpdate, "duration")
|
|
||||||
if val != "" {
|
|
||||||
d, err := time.ParseDuration(val)
|
d, err := time.ParseDuration(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%w: could not parse duration", ErrInvalidArg)
|
return nil, fmt.Errorf("%w: could not parse duration", ErrInvalidArg)
|
||||||
}
|
}
|
||||||
args.Duration = d
|
args.Duration = d
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if val, ok := fields["recurrer"]; ok {
|
if val, ok := fields["recurrer"]; ok {
|
||||||
args.NeedUpdate = append(args.NeedUpdate, "recurrer")
|
|
||||||
if val != "" {
|
|
||||||
rec := item.NewRecurrer(val)
|
rec := item.NewRecurrer(val)
|
||||||
if rec == nil {
|
if rec == nil {
|
||||||
return nil, fmt.Errorf("%w: could not parse recurrer", ErrInvalidArg)
|
return nil, fmt.Errorf("%w: could not parse recurrer", ErrInvalidArg)
|
||||||
}
|
}
|
||||||
args.Recurrer = rec
|
args.Recurrer = rec
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return &Update{args}, nil
|
return &Update{args}, nil
|
||||||
}
|
}
|
||||||
|
@ -123,19 +107,19 @@ func (u Update) Do(deps Dependencies) (CommandResult, error) {
|
||||||
if u.args.Title != "" {
|
if u.args.Title != "" {
|
||||||
tsk.Title = u.args.Title
|
tsk.Title = u.args.Title
|
||||||
}
|
}
|
||||||
if slices.Contains(u.args.NeedUpdate, "project") {
|
if u.args.Project != "" {
|
||||||
tsk.Project = u.args.Project
|
tsk.Project = u.args.Project
|
||||||
}
|
}
|
||||||
if slices.Contains(u.args.NeedUpdate, "date") {
|
if !u.args.Date.IsZero() {
|
||||||
tsk.Date = u.args.Date
|
tsk.Date = u.args.Date
|
||||||
}
|
}
|
||||||
if slices.Contains(u.args.NeedUpdate, "time") {
|
if !u.args.Time.IsZero() {
|
||||||
tsk.Time = u.args.Time
|
tsk.Time = u.args.Time
|
||||||
}
|
}
|
||||||
if slices.Contains(u.args.NeedUpdate, "duration") {
|
if u.args.Duration != 0 {
|
||||||
tsk.Duration = u.args.Duration
|
tsk.Duration = u.args.Duration
|
||||||
}
|
}
|
||||||
if slices.Contains(u.args.NeedUpdate, "recurrer") {
|
if u.args.Recurrer != nil {
|
||||||
tsk.Recurrer = u.args.Recurrer
|
tsk.Recurrer = u.args.Recurrer
|
||||||
tsk.RecurNext = tsk.Recurrer.First()
|
tsk.RecurNext = tsk.Recurrer.First()
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (t *SqliteTask) FindMany(params storage.TaskListParams) ([]item.Task, error
|
||||||
query := `SELECT id, title, project, date, time, duration, recurrer FROM tasks`
|
query := `SELECT id, title, project, date, time, duration, recurrer FROM tasks`
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
|
|
||||||
where := make([]string, 0)
|
where := []string{`recurrer = ''`}
|
||||||
if params.HasRecurrer {
|
if params.HasRecurrer {
|
||||||
where[0] = `recurrer != ''`
|
where[0] = `recurrer != ''`
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,10 @@ func (r *Recur) Recur(until item.Date) error {
|
||||||
newRecurNext := item.FirstRecurAfter(i.Recurrer, i.RecurNext)
|
newRecurNext := item.FirstRecurAfter(i.Recurrer, i.RecurNext)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
if newRecurNext.After(until) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// spawn instance
|
// spawn instance
|
||||||
newItem := i
|
newItem := i
|
||||||
newItem.ID = uuid.New().String()
|
newItem.ID = uuid.New().String()
|
||||||
|
@ -64,10 +68,6 @@ func (r *Recur) Recur(until item.Date) error {
|
||||||
r.logger.Info("spawned instance", "newID", newItem.ID, "date", newItem.Date)
|
r.logger.Info("spawned instance", "newID", newItem.ID, "date", newItem.Date)
|
||||||
|
|
||||||
newRecurNext = item.FirstRecurAfter(i.Recurrer, newRecurNext)
|
newRecurNext = item.FirstRecurAfter(i.Recurrer, newRecurNext)
|
||||||
|
|
||||||
if newRecurNext.After(until) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update recurrer
|
// update recurrer
|
||||||
|
|
Loading…
Reference in New Issue