Exemplo n.º 1
0
// add creates an entry and posts it to the server
func add() {
	e := entry.Entry{Msg: *msg}
	e.SetDuration(*dur)
	jsonRequest("POST", "/entries", &e)

	fmt.Println("Activity Added:", e.Msg, "|", e.TimeString())
}
Exemplo n.º 2
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())
}
Exemplo n.º 3
0
// 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)
}
Exemplo n.º 4
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})
}