diff --git a/client/todo/add.go b/client/todo/add.go index 13eb421..3dbd3a4 100644 --- a/client/todo/add.go +++ b/client/todo/add.go @@ -28,7 +28,7 @@ func addAction(context context.Context, c *cli.Command) error { var newTodos []common.Todo var adding = true for adding { - newTodos = append(newTodos, createNewTodo()) + newTodos = append(newTodos, CreateNewTodo()) if !common.AskUserBool("Want to add more?") { adding = false } @@ -44,8 +44,7 @@ func addAction(context context.Context, c *cli.Command) error { return nil } -func createNewTodo() common.Todo { - +func CreateNewTodo() common.Todo { labelInput := common.AskUserString("Labels (comma separated):\n") labelSlice := strings.Split(labelInput, ",") for i, l := range labelSlice { diff --git a/client/todo/todo.go b/client/todo/todo.go index bd8ce2f..ce52609 100644 --- a/client/todo/todo.go +++ b/client/todo/todo.go @@ -9,7 +9,6 @@ import ( "os" "strconv" "strings" - "time" "gitea.kleinsense.nl/DariusKlein/kleinTodo/common" "github.com/urfave/cli/v3" @@ -56,7 +55,7 @@ func todo(context context.Context, c *cli.Command) error { case "d", "delete": todos = handleDelete(scanner, todos, store) case "a", "add": - todos = handleAdd(scanner, todos, store) + todos = handleAdd(todos, store) case "q", "quit": fmt.Println("Goodbye!") return nil // Exit the program @@ -154,26 +153,18 @@ func handleUpdate(scanner *bufio.Scanner, todos []common.Todo, store *common.Bol } // handleAdd prompts for the details of a new item. -func handleAdd(scanner *bufio.Scanner, todos []common.Todo, store *common.BoltStore) []common.Todo { - fmt.Print("Enter the name of the new task: ") - scanner.Scan() - name := strings.TrimSpace(scanner.Text()) +func handleAdd(todos []common.Todo, store *common.BoltStore) []common.Todo { - fmt.Print("Enter the description: ") - scanner.Scan() - description := strings.TrimSpace(scanner.Text()) + newTodo := CreateNewTodo() todoList := common.TodoList{Todos: todos} - _, exists := todoList.FindByName(name) + _, exists := todoList.FindByName(newTodo.Name) if exists { - log.Fatalf("Item '%s' already exists.", name) + log.Fatalf("Item '%s' already exists.", newTodo.Name) return todos } - newTodo := common.Todo{ - Name: name, Description: description, Status: common.NotStarted, Owner: cfg.Server.Credentials.Username, LastModified: time.Now(), - } err := newTodo.Store(store, cfg.Server.Credentials.Username) if err != nil { slog.Error(err.Error())