This commit is contained in:
parent
7d70abecec
commit
e0c04fb9d1
@ -28,7 +28,7 @@ func addAction(context context.Context, c *cli.Command) error {
|
|||||||
var newTodos []common.Todo
|
var newTodos []common.Todo
|
||||||
var adding = true
|
var adding = true
|
||||||
for adding {
|
for adding {
|
||||||
newTodos = append(newTodos, createNewTodo())
|
newTodos = append(newTodos, CreateNewTodo())
|
||||||
if !common.AskUserBool("Want to add more?") {
|
if !common.AskUserBool("Want to add more?") {
|
||||||
adding = false
|
adding = false
|
||||||
}
|
}
|
||||||
@ -44,8 +44,7 @@ func addAction(context context.Context, c *cli.Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNewTodo() common.Todo {
|
func CreateNewTodo() common.Todo {
|
||||||
|
|
||||||
labelInput := common.AskUserString("Labels (comma separated):\n")
|
labelInput := common.AskUserString("Labels (comma separated):\n")
|
||||||
labelSlice := strings.Split(labelInput, ",")
|
labelSlice := strings.Split(labelInput, ",")
|
||||||
for i, l := range labelSlice {
|
for i, l := range labelSlice {
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"gitea.kleinsense.nl/DariusKlein/kleinTodo/common"
|
"gitea.kleinsense.nl/DariusKlein/kleinTodo/common"
|
||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
@ -56,7 +55,7 @@ func todo(context context.Context, c *cli.Command) error {
|
|||||||
case "d", "delete":
|
case "d", "delete":
|
||||||
todos = handleDelete(scanner, todos, store)
|
todos = handleDelete(scanner, todos, store)
|
||||||
case "a", "add":
|
case "a", "add":
|
||||||
todos = handleAdd(scanner, todos, store)
|
todos = handleAdd(todos, store)
|
||||||
case "q", "quit":
|
case "q", "quit":
|
||||||
fmt.Println("Goodbye!")
|
fmt.Println("Goodbye!")
|
||||||
return nil // Exit the program
|
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.
|
// handleAdd prompts for the details of a new item.
|
||||||
func handleAdd(scanner *bufio.Scanner, todos []common.Todo, store *common.BoltStore) []common.Todo {
|
func handleAdd(todos []common.Todo, store *common.BoltStore) []common.Todo {
|
||||||
fmt.Print("Enter the name of the new task: ")
|
|
||||||
scanner.Scan()
|
|
||||||
name := strings.TrimSpace(scanner.Text())
|
|
||||||
|
|
||||||
fmt.Print("Enter the description: ")
|
newTodo := CreateNewTodo()
|
||||||
scanner.Scan()
|
|
||||||
description := strings.TrimSpace(scanner.Text())
|
|
||||||
|
|
||||||
todoList := common.TodoList{Todos: todos}
|
todoList := common.TodoList{Todos: todos}
|
||||||
|
|
||||||
_, exists := todoList.FindByName(name)
|
_, exists := todoList.FindByName(newTodo.Name)
|
||||||
if exists {
|
if exists {
|
||||||
log.Fatalf("Item '%s' already exists.", name)
|
log.Fatalf("Item '%s' already exists.", newTodo.Name)
|
||||||
return todos
|
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)
|
err := newTodo.Store(store, cfg.Server.Credentials.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user