Gisle Aune
3 years ago
13 changed files with 237 additions and 52 deletions
-
8app/api/devices.go
-
27app/client/handler.go
-
2app/services/events.go
-
2app/services/synclights.go
-
45cmd/lucy/handlercmd.go
-
4cmd/lucy/help.go
-
15cmd/lucy/main.go
-
47cmd/lucy/tables.go
-
6go.sum
-
11install-lucy.sh
-
13internal/mysql/devicerepo.go
-
10models/device.go
-
21models/eventhandler.go
@ -0,0 +1,27 @@ |
|||||
|
package client |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"git.aiterp.net/lucifer/new-server/models" |
||||
|
) |
||||
|
|
||||
|
func (client *Client) GetHandlers(ctx context.Context, fetchStr string) ([]models.EventHandler, error) { |
||||
|
handlers := make([]models.EventHandler, 0, 16) |
||||
|
err := client.Fetch(ctx, "GET", "/api/event-handlers", &handlers, nil) |
||||
|
if err != nil { |
||||
|
return nil, err |
||||
|
} |
||||
|
|
||||
|
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 |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"git.aiterp.net/lucifer/new-server/app/client" |
||||
|
"git.aiterp.net/lucifer/new-server/models" |
||||
|
"log" |
||||
|
"os" |
||||
|
) |
||||
|
|
||||
|
func handlerCmd( |
||||
|
ctx context.Context, |
||||
|
c client.Client, |
||||
|
) { |
||||
|
cmd := parseCommand(os.Args[2:]) |
||||
|
|
||||
|
switch cmd.Name { |
||||
|
case "list": |
||||
|
handlers, err := c.GetHandlers(ctx, cmd.Params.Get(0).StringOr("all")) |
||||
|
if err != nil { |
||||
|
log.Fatalln(err) |
||||
|
} |
||||
|
|
||||
|
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: |
||||
|
if cmd.Name != "help" { |
||||
|
log.Println("Unknown command:", cmd.Name) |
||||
|
} |
||||
|
|
||||
|
_, _ = fmt.Fprintln(os.Stderr, helpString[1:]) |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
printf "Building lucy...\n" |
||||
|
go mod download || exit 1 |
||||
|
go build -ldflags "-w -s" -o lucy ./cmd/lucy || exit 1 |
||||
|
|
||||
|
printf "Removing old lucy...\n" |
||||
|
sudo rm /usr/local/bin/lucy > /dev/null 2>&1 |
||||
|
|
||||
|
printf "Installing...\n" |
||||
|
sudo mv ./lucy /usr/local/bin/lucy |
Write
Preview
Loading…
Cancel
Save
Reference in new issue