2025-08-23 13:28:48 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-08-23 19:14:16 +02:00
|
|
|
"fmt"
|
2025-08-23 13:28:48 +02:00
|
|
|
"log"
|
2025-08-23 19:14:16 +02:00
|
|
|
"log/slog"
|
|
|
|
|
"maps"
|
2025-08-23 13:28:48 +02:00
|
|
|
"net/mail"
|
|
|
|
|
"os"
|
|
|
|
|
|
2025-08-23 19:14:16 +02:00
|
|
|
"gitea.kleinsense.nl/DariusKlein/kleinTodo/client/todo/clientCommon/config"
|
|
|
|
|
"gitea.kleinsense.nl/DariusKlein/kleinTodo/common"
|
2025-08-23 13:28:48 +02:00
|
|
|
"github.com/urfave/cli/v3"
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-23 19:14:16 +02:00
|
|
|
var cfg config.Config
|
|
|
|
|
|
2025-08-23 13:28:48 +02:00
|
|
|
func main() {
|
2025-08-23 19:14:16 +02:00
|
|
|
var err error
|
|
|
|
|
cfg, err = config.ReadConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error(err.Error())
|
|
|
|
|
}
|
2025-08-23 13:28:48 +02:00
|
|
|
|
|
|
|
|
app := &cli.Command{
|
|
|
|
|
Name: "Todo",
|
|
|
|
|
Usage: "kleinTodo client",
|
2025-08-23 19:14:16 +02:00
|
|
|
UsageText: "Todo [command] [arguments...]",
|
2025-08-23 13:28:48 +02:00
|
|
|
Version: "v0.1.0",
|
|
|
|
|
HideVersion: true,
|
|
|
|
|
Authors: []any{
|
|
|
|
|
mail.Address{
|
|
|
|
|
Name: "Darius",
|
|
|
|
|
Address: "darius.klein@dariusklein.nl",
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-08-23 19:14:16 +02:00
|
|
|
DefaultCommand: "todo",
|
|
|
|
|
Commands: commands(),
|
2025-08-23 13:28:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := app.Run(context.Background(), os.Args); err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-23 19:14:16 +02:00
|
|
|
|
|
|
|
|
func commands() []*cli.Command {
|
|
|
|
|
return []*cli.Command{
|
|
|
|
|
config.Category(),
|
|
|
|
|
Login(),
|
|
|
|
|
Sync(),
|
|
|
|
|
{
|
|
|
|
|
Name: "todo",
|
|
|
|
|
Usage: "print todo items",
|
|
|
|
|
Action: printTodo,
|
|
|
|
|
HideHelpCommand: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func printTodo(context context.Context, c *cli.Command) error {
|
|
|
|
|
fmt.Printf("Todo items:\n")
|
|
|
|
|
store, err := common.GetTodoDataStore()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
serverTodos := store.GetTodos(cfg.Server.Credentials.Username)
|
|
|
|
|
|
|
|
|
|
var index = 1
|
|
|
|
|
|
|
|
|
|
for todo := range maps.Values(serverTodos) {
|
|
|
|
|
todo.PrintIndexed(index)
|
|
|
|
|
index++
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|