示例#1
0
文件: todo.go 项目: elos/elos
func (c *TodoCommand) runStart() int {
	tsk, index := c.promptSelectTask()
	if index < 0 {
		return failure
	}

	// task.Start(tsk) is idempotent, and simply won't
	// do anything if the task is in progress, but we
	// want to indicate to the user if they are not
	// actually starting the task
	if task.InProgress(tsk) {
		c.UI.Warn("Task is already in progress")
		return success
	}

	task.Start(tsk)

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

	c.UI.Info(fmt.Sprintf("Started '%s'", tsk.Name))

	return success
}
示例#2
0
文件: todo.go 项目: elos/elos
// runSuggest runs the 'suggest' subcommand, which uses elos'
// most important task algorithm to suggest the one to work on
func (c *TodoCommand) runSuggest() int {
	if len(c.tasks) == 0 {
		c.UI.Info("You have no tasks")
		return success
	}

	suggested := task.NewGraph(c.tasks).Suggest()

	tagNames := ""
	tags := suggested.Tags
	for _, t := range tags {
		tagNames += fmt.Sprintf("[%s]", t)
	}
	if tagNames != "" {
		tagNames += ": "
	}
	c.UI.Output(fmt.Sprintf("%s %s", tagNames, suggested.Name))

	if b, err := yesNo(c.UI, fmt.Sprintf("Start %s?", suggested.Name)); err != nil {
		c.errorf("Input Error: %s", err)
		return failure
	} else if b {
		task.Start(suggested)

		if err := c.DB.Save(suggested); err != nil {
			c.errorf("saving task: %s", err)
			return failure
		} else {
			c.UI.Output(fmt.Sprintf("Started '%s'", suggested.Name))
		}
	}

	return success
}
示例#3
0
文件: todo_test.go 项目: elos/elos
// TestTodoCurrent tests the `current` subcommand
func TestTodoCurrent(t *testing.T) {
	ui, db, user, c := newMockTodoCommand(t)

	// setup that there is one task
	tsk := newTestTask(t, db, user)
	taskName := "task name"
	tsk.Name = taskName
	task.Start(tsk)
	if err := db.Save(tsk); err != nil {
		t.Fatal(err)
	}

	// run the effect of `elos todo complete`
	code := c.Run([]string{"current"})

	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, taskName) {
		t.Fatalf("Output should have contained the running task's name: '%s'", taskName)
	}
}