Example #1
0
/*
	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())
}
Example #2
0
/*
	Checks for active entry, asks to end it.
	Creates new activity
*/
func start() {
	//if active entry, ask to end
	var e entry.Entry
	jsonRequest("GET", "/entries/latest", &e)

	// if this activity is still going
	if e.Started() && !e.Ended() {
		// do they want to close the old one?
		if confirm(fmt.Sprintf("End Activity (%s)", e.Msg)) {
			stop(false)
		} else {
			return
		}
	}
	//post the new one
	jsonRequest("POST", "/entries", &entry.Entry{Msg: *msg})
}