示例#1
0
文件: todo.go 项目: elos/elos
// runGoals runs the 'goals' subcommand, which prints the user's goals
func (c *TodoCommand) runGoals() int {
	tasks, err := tag.TasksFor(c.DB, c.UserID, "GOAL")
	if err != nil {
		c.errorf("retrieving GOAL tasks: %s", err)
		return failure
	}

	taskIds := make(map[data.ID]bool)
	for i := range tasks {
		if !task.IsComplete(tasks[i]) {
			taskIds[tasks[i].ID()] = true
		}
	}

	if len(taskIds) == 0 {
		c.UI.Output("No goals set. Use `elos todo goal` to add a goal.")
		return success
	}

	c.UI.Output("Current Goals:")
	c.printTaskList(func(t *models.Task) bool {
		_, ok := taskIds[t.ID()]
		return ok
	})

	return success
}
示例#2
0
文件: todo.go 项目: elos/elos
// runListTag runs the 'list -t' subcommand. It prints a list of the
// tasks cached in c.tasks according to the specified tag.
func (c *TodoCommand) runListTag() int {
	tg := c.promptSelectTag()
	if tg == "" {
		return success
	}

	tasks, err := tag.TasksFor(c.DB, c.UserID, tg)
	if err != nil {
		c.errorf("retrieving tasks: %s", err)
		return failure
	}

	ids := make(map[data.ID]bool)
	for _, t := range tasks {
		ids[t.ID()] = true
	}

	c.UI.Output(fmt.Sprintf("%s Tasks:", tg))
	c.printTaskList(func(t *models.Task) bool {
		_, ok := ids[t.ID()]
		return ok
	})
	return success
}
示例#3
0
文件: todo_test.go 项目: elos/elos
// TestTodoGoal tests the `goal` subcommand
func TestTodoGoal(t *testing.T) {
	ui, db, user, c := newMockTodoCommand(t)

	// load a task into the db
	task := newTestTask(t, db, user)
	task.Name = "Take out the trash"
	if err := db.Save(task); err != nil {
		t.Fatal(err)
	}

	// load input
	input := strings.Join([]string{
		"0",
	}, "\n")
	ui.InputReader = bytes.NewBufferString(input)

	t.Log("running: `elos todo goal`")
	code := c.Run([]string{"goal"})
	t.Log("command 'goal' terminated")

	errput := ui.ErrorWriter.String()
	output := ui.OutputWriter.String()
	t.Logf("Error output:\n %s", errput)
	t.Logf("Output:\n %s", output)

	// verify there were no errors
	if errput != "" {
		t.Fatalf("Expected no error output, got: %s", errput)
	}

	// verify success
	if code != success {
		t.Fatalf("Expected successful exit code along with empty error output.")
	}

	// verify some of the output
	if !strings.Contains(output, "0)") {
		t.Fatalf("Output should have contained a 0) for listing tasks")
	}

	if !strings.Contains(output, "Which number?") {
		t.Fatalf("Output should have asked for a task number")
	}

	t.Log("Checking that the task is now a member of goals")

	// reload task:
	if err := db.PopulateByID(task); err != nil {
		t.Fatal(err)
	}

	t.Logf("Task:\n%+v", task)

	tg := "GOAL"

	t.Logf("GOALS tag:\n%+v", tg)

	tasks, err := tag.TasksFor(db, c.UserID, tg)
	if err != nil {
		t.Fatal(err)
	}

	if len(tasks) != 1 {
		t.Fatalf("Expected goals tag to contain just one task, contained: %d", len(tasks))
	}

	if tasks[0].Id != task.Id {
		t.Fatal("Expected task to now be a part of goals")
	}
}