/* Find the active entry. Ask user to enter a message if none has been set yet. Set the end time to now, and save. */ func stop(fromCommand bool) { //if active entry, ask to end var e entry.Entry jsonRequest("GET", "/entries/latest", &e) // check for active entry if e.Started() && e.Ended() { fmt.Println("No active entry") return } if fromCommand && *msg != "" { e.Msg = *msg } if e.Msg == "" { fmt.Print("Enter a message for this entry: ") in := bufio.NewReader(os.Stdin) input, _, err := in.ReadLine() doPanic(err) e.Msg = string(input) } e.End = time.Now() path := fmt.Sprintf("/entries/%d", e.Id) jsonRequest("PUT", path, &e) fmt.Println("Activity Finished:", e.Msg, "|", e.TimeString()) }
// edit updates an existing entry and then saves it to the server. func edit() { var e entry.Entry path := fmt.Sprintf("/entries/%d", id) jsonRequest("GET", path, &e) e.Msg = *msg e.SetDuration(*dur) jsonRequest("PUT", path, &e) }