Browse Source

lucy handler delete

feature-colorvalue2
Stian Fredrik Aune 3 years ago
parent
commit
b1fa52e53f
  1. 11
      app/client/handler.go
  2. 13
      cmd/lucy/handlercmd.go
  3. 5
      cmd/lucy/help.go
  4. 2
      install-lucy.sh

11
app/client/handler.go

@ -2,6 +2,7 @@ package client
import ( import (
"context" "context"
"fmt"
"git.aiterp.net/lucifer/new-server/models" "git.aiterp.net/lucifer/new-server/models"
) )
@ -14,3 +15,13 @@ func (client *Client) GetHandlers(ctx context.Context, fetchStr string) ([]model
return handlers, nil return handlers, nil
} }
func (client *Client) DeleteHandler(ctx context.Context, id int) (*models.EventHandler, error) {
var handler models.EventHandler
err := client.Fetch(ctx, "DELETE", fmt.Sprintf("/api/event-handlers/%d", id), &handler, nil)
if err != nil {
return nil, err
}
return &handler, nil
}

13
cmd/lucy/handlercmd.go

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"git.aiterp.net/lucifer/new-server/app/client" "git.aiterp.net/lucifer/new-server/app/client"
"git.aiterp.net/lucifer/new-server/models"
"log" "log"
"os" "os"
) )
@ -22,6 +23,18 @@ func handlerCmd(
} }
WriteHandlerInfoTable(os.Stdout, handlers) WriteHandlerInfoTable(os.Stdout, handlers)
case "delete":
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)

5
cmd/lucy/help.go

@ -7,8 +7,11 @@ EXAMPLES
lucy set tag:Hexagon color=hs:35,1 intensity=0.3 lucy set tag:Hexagon color=hs:35,1 intensity=0.3
lucy run SetProfile name=evening lucy run SetProfile name=evening
EVENT HANDLER COMMANDS
handler list
handler delete <id>
DEVICE COMMANDS DEVICE COMMANDS
handler list <search>
list <search> list <search>
set <search> <power=B> <color=C> <intensity=F> <temperature=N> set <search> <power=B> <color=C> <intensity=F> <temperature=N>
tag <search> <[+/-]tag-name> tag <search> <[+/-]tag-name>

2
install-lucy.sh

@ -5,7 +5,7 @@ go mod download || exit 1
go build -ldflags "-w -s" -o lucy ./cmd/lucy || exit 1 go build -ldflags "-w -s" -o lucy ./cmd/lucy || exit 1
printf "Removing old lucy...\n" printf "Removing old lucy...\n"
sudo rm /usr/local/bin/lucy > /dev/null 2&>1
sudo rm /usr/local/bin/lucy > /dev/null 2>&1
printf "Installing...\n" printf "Installing...\n"
sudo mv ./lucy /usr/local/bin/lucy sudo mv ./lucy /usr/local/bin/lucy
Loading…
Cancel
Save