diff --git a/plan/command/update.go b/plan/command/update.go index 5c7c2e9..685e1b2 100644 --- a/plan/command/update.go +++ b/plan/command/update.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "strconv" "strings" "time" @@ -13,6 +14,7 @@ type Update struct { eventRepo storage.Event syncRepo storage.Sync argSet *ArgSet + localID int } 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 { - if len(main) == 0 || main[0] != "update" { + if len(main) < 2 || main[0] != "update" { 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 if len(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 { - - return nil -} - -func UpdateOld(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync, localID int, nameStr, onStr, atStr, frStr string) error { + as := update.argSet var id string - idMap, err := localRepo.FindAll() + idMap, err := update.localIDRepo.FindAll() if err != nil { return fmt.Errorf("could not get local ids: %v", err) } for eid, lid := range idMap { - if localID == lid { + if update.localID == lid { id = eid } } @@ -72,13 +76,13 @@ func UpdateOld(localRepo storage.LocalID, eventRepo storage.Event, syncRepo stor return fmt.Errorf("could not find local id") } - e, err := eventRepo.Find(id) + e, err := update.eventRepo.Find(id) if err != nil { return fmt.Errorf("could not find event") } - if nameStr != "" { - e.Title = nameStr + if as.Main != "" { + e.Title = as.Main } if onStr != "" || atStr != "" { oldStart := e.Start