Пример #1
0
Файл: todo.go Проект: elos/elos
// runComplete executes the "elos todo complete" command.
//
// Complete first prints a numbered list of the user's tasks.
// Then it prompts the user for which number task to complete.
// The user's tasks list (c.tasks) only contains incomplete tasks.
// If the task is in progress, it is also stopped. Finally, the task is
// removed from the c.tasks.
func (c *TodoCommand) runComplete() int {
	tsk, index := c.promptSelectTask()
	if index < 0 {
		return failure
	}

	task.StopAndComplete(tsk)

	err := c.DB.Save(tsk)
	if err != nil {
		c.errorf("(subcommand complete) Error: %s", err)
		return failure
	}

	// remove the tasks from the list becuase it is now complete
	c.removeTask(index)

	c.UI.Info(fmt.Sprintf("Completed '%s'", tsk.Name))
	c.UI.Info(fmt.Sprintf("Worked for %s total", task.TimeSpent(tsk)))

	return success
}
Пример #2
0
Файл: todo.go Проект: elos/elos
// printTaskList prints the list of tasks, with deadline and salience info
// the list is numbered, and can be useful for tasks that involve the user
// looking at / selecting a particular task (however use promptSelectTask
// for the case of selecting a single task from the c.tasks)
func (c *TodoCommand) printTaskList(selectors ...func(*models.Task) bool) {
PrintLoop:
	for i, t := range c.tasks {
		for i := range selectors {
			if !selectors[i](t) {
				continue PrintLoop
			}
		}

		// Tags
		tagList := ""
		for _, n := range t.Tags {
			tagList += fmt.Sprintf(" [%s]", n)
		}
		if tagList != "" {
			tagList += ": "
		} else {
			tagList = " " + tagList
		}

		// Deadline
		deadline := ""
		if !t.DeadlineAt.IsZero() {
			deadline = fmt.Sprintf("(%s)", t.DeadlineAt.Time().Local().Format("Mon Jan 2 15:04"))
		}

		c.UI.Output(fmt.Sprintf("%d)%s%s %s\n\tSalience:%f; Time Spent:%s", i, tagList, t.Name, deadline, task.Salience(t), task.TimeSpent(t)))
	}
}