示例#1
0
文件: waid.go 项目: rharriso/waid
// 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())
}
示例#2
0
文件: waid.go 项目: rharriso/waid
/*
	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())
}
示例#3
0
文件: waid.go 项目: rharriso/waid
// 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)
}
示例#4
0
文件: waid.go 项目: rharriso/waid
/*
	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})
}