wip
This commit is contained in:
parent
9aec6b1b63
commit
f132031dc6
|
@ -2,6 +2,7 @@ package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -13,6 +14,7 @@ type Update struct {
|
||||||
eventRepo storage.Event
|
eventRepo storage.Event
|
||||||
syncRepo storage.Sync
|
syncRepo storage.Sync
|
||||||
argSet *ArgSet
|
argSet *ArgSet
|
||||||
|
localID int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUpdate(localIDRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync) Command {
|
func NewUpdate(localIDRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync) Command {
|
||||||
|
@ -32,9 +34,15 @@ func NewUpdate(localIDRepo storage.LocalID, eventRepo storage.Event, syncRepo st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (update *Update) Parse(main []string, flags map[string]string) error {
|
func (update *Update) Parse(main []string, flags map[string]string) error {
|
||||||
if len(main) == 0 || main[0] != "update" {
|
if len(main) < 2 || main[0] != "update" {
|
||||||
return ErrWrongCommand
|
return ErrWrongCommand
|
||||||
}
|
}
|
||||||
|
localID, err := strconv.Atoi(main[1])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("not a local id: %v", main[1])
|
||||||
|
}
|
||||||
|
update.localID = localID
|
||||||
|
|
||||||
as := update.argSet
|
as := update.argSet
|
||||||
if len(main) > 1 {
|
if len(main) > 1 {
|
||||||
as.Main = strings.Join(main[1:], " ")
|
as.Main = strings.Join(main[1:], " ")
|
||||||
|
@ -53,18 +61,14 @@ func (update *Update) Parse(main []string, flags map[string]string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (update *Update) Do() error {
|
func (update *Update) Do() error {
|
||||||
|
as := update.argSet
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateOld(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync, localID int, nameStr, onStr, atStr, frStr string) error {
|
|
||||||
var id string
|
var id string
|
||||||
idMap, err := localRepo.FindAll()
|
idMap, err := update.localIDRepo.FindAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not get local ids: %v", err)
|
return fmt.Errorf("could not get local ids: %v", err)
|
||||||
}
|
}
|
||||||
for eid, lid := range idMap {
|
for eid, lid := range idMap {
|
||||||
if localID == lid {
|
if update.localID == lid {
|
||||||
id = eid
|
id = eid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,13 +76,13 @@ func UpdateOld(localRepo storage.LocalID, eventRepo storage.Event, syncRepo stor
|
||||||
return fmt.Errorf("could not find local id")
|
return fmt.Errorf("could not find local id")
|
||||||
}
|
}
|
||||||
|
|
||||||
e, err := eventRepo.Find(id)
|
e, err := update.eventRepo.Find(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not find event")
|
return fmt.Errorf("could not find event")
|
||||||
}
|
}
|
||||||
|
|
||||||
if nameStr != "" {
|
if as.Main != "" {
|
||||||
e.Title = nameStr
|
e.Title = as.Main
|
||||||
}
|
}
|
||||||
if onStr != "" || atStr != "" {
|
if onStr != "" || atStr != "" {
|
||||||
oldStart := e.Start
|
oldStart := e.Start
|
||||||
|
|
Loading…
Reference in New Issue