You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
833 B

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "git.aiterp.net/lucifer/new-server/app/client"
  6. "git.aiterp.net/lucifer/new-server/models"
  7. "log"
  8. "os"
  9. )
  10. func handlerCmd(
  11. ctx context.Context,
  12. c client.Client,
  13. ) {
  14. cmd := parseCommand(os.Args[2:])
  15. switch cmd.Name {
  16. case "list":
  17. handlers, err := c.GetHandlers(ctx, cmd.Params.Get(0).StringOr("all"))
  18. if err != nil {
  19. log.Fatalln(err)
  20. }
  21. WriteHandlerInfoTable(os.Stdout, handlers)
  22. case "delete":
  23. id := cmd.Params.Get(0).Int()
  24. if id == nil {
  25. log.Fatalln("ID missing")
  26. }
  27. handler, err := c.DeleteHandler(ctx, *id)
  28. if err != nil {
  29. log.Fatalln(err)
  30. }
  31. WriteHandlerInfoTable(os.Stdout, []models.EventHandler{*handler})
  32. default:
  33. if cmd.Name != "help" {
  34. log.Println("Unknown command:", cmd.Name)
  35. }
  36. _, _ = fmt.Fprintln(os.Stderr, helpString[1:])
  37. }
  38. }