56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"gitea.kleinsense.nl/DariusKlein/kleinTodo/common"
|
||
|
|
"github.com/urfave/cli/v3"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Add Command
|
||
|
|
func Add() *cli.Command {
|
||
|
|
return &cli.Command{
|
||
|
|
Name: "add",
|
||
|
|
Usage: "add todo item (s)",
|
||
|
|
Action: addAction,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// addAction logic for Template
|
||
|
|
func addAction(context context.Context, c *cli.Command) error {
|
||
|
|
store, err := common.GetTodoDataStore()
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
var newTodos []common.Todo
|
||
|
|
var adding = true
|
||
|
|
for adding {
|
||
|
|
newTodos = append(newTodos, createNewTodo())
|
||
|
|
if !common.AskUserBool("Want to add more?") {
|
||
|
|
adding = false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, t := range newTodos {
|
||
|
|
err := t.Store(store, cfg.Server.Credentials.Username)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func createNewTodo() common.Todo {
|
||
|
|
return common.Todo{
|
||
|
|
Name: common.AskUserString("Name:\n"),
|
||
|
|
Description: common.AskUserString("Description:\n"),
|
||
|
|
Status: common.AskUserString(fmt.Sprintf("Status(%s, %s, %s, %s, %s, %s):\n",
|
||
|
|
common.NotStarted, common.Done, common.WIP, common.Pending, common.Blocked, common.Failed,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
Owner: cfg.Server.Credentials.Username,
|
||
|
|
}
|
||
|
|
}
|