Browse Source

enable 'lucy handler delete all'

feature-colorvalue2
Stian Fredrik Aune 3 years ago
parent
commit
f4e584938b
  1. 34
      cmd/lucy/handlercmd.go

34
cmd/lucy/handlercmd.go

@ -76,17 +76,33 @@ func handlerCmd(
WriteHandlerInfoTable(os.Stdout, []models.EventHandler{*returned}) WriteHandlerInfoTable(os.Stdout, []models.EventHandler{*returned})
case "delete": case "delete":
id := cmd.Params.Get(0).Int()
if id == nil {
log.Fatalln("ID missing")
}
if cmd.Params.Get(0).StringOr("_not") == "all" {
handlers, err := c.GetHandlers(ctx)
if err != nil {
log.Fatalln(err)
}
handler, err := c.DeleteHandler(ctx, *id)
if err != nil {
log.Fatalln(err)
}
for _, handler := range handlers {
_, err = c.DeleteHandler(ctx, handler.ID)
if err != nil {
log.Fatalln(err)
}
}
WriteHandlerInfoTable(os.Stdout, []models.EventHandler{*handler})
log.Printf("Deleted %d handlers", len(handlers))
} else {
id := cmd.Params.Get(0).Int()
if id == nil {
log.Fatalln("ID missing")
}
handler, err := c.DeleteHandler(ctx, *id)
if err != nil {
log.Fatalln(err)
}
WriteHandlerInfoTable(os.Stdout, []models.EventHandler{*handler})
}
default: default:
if cmd.Name != "help" { if cmd.Name != "help" {
log.Println("Unknown command:", cmd.Name) log.Println("Unknown command:", cmd.Name)

Loading…
Cancel
Save