-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdevices.go
More file actions
86 lines (80 loc) · 2.11 KB
/
Copy pathdevices.go
File metadata and controls
86 lines (80 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cmd
import (
"github.com/nextlevelbuilder/goclaw-cli/internal/output"
"github.com/nextlevelbuilder/goclaw-cli/internal/tui"
"github.com/spf13/cobra"
)
var devicesCmd = &cobra.Command{Use: "devices", Short: "Manage paired devices"}
var devicesListCmd = &cobra.Command{
Use: "list", Short: "List paired devices",
RunE: func(cmd *cobra.Command, args []string) error {
ws, err := newWS("cli")
if err != nil {
return err
}
if _, err := ws.Connect(); err != nil {
return err
}
defer ws.Close()
data, err := ws.Call("device.pair.list", map[string]any{})
if err != nil {
return err
}
if cfg.OutputFormat != "table" {
printer.Print(unmarshalList(data))
return nil
}
tbl := output.NewTable("ID", "NAME", "USER", "STATUS", "PAIRED_AT", "LAST_SEEN")
for _, d := range unmarshalList(data) {
tbl.AddRow(str(d, "id"), str(d, "device_name"), str(d, "user_id"),
str(d, "status"), str(d, "paired_at"), str(d, "last_seen_at"))
}
printer.Print(tbl)
return nil
},
}
var devicesRevokeCmd = &cobra.Command{
Use: "revoke <id>", Short: "Revoke a paired device", Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if !tui.Confirm("Revoke this device?", cfg.Yes) {
return nil
}
ws, err := newWS("cli")
if err != nil {
return err
}
if _, err := ws.Connect(); err != nil {
return err
}
defer ws.Close()
_, err = ws.Call("device.pair.revoke", map[string]any{"id": args[0]})
if err != nil {
return err
}
printer.Success("Device revoked")
return nil
},
}
var devicesPairingStatusCmd = &cobra.Command{
Use: "pairing-status", Short: "Check browser pairing status",
RunE: func(cmd *cobra.Command, args []string) error {
ws, err := newWS("cli")
if err != nil {
return err
}
if _, err := ws.Connect(); err != nil {
return err
}
defer ws.Close()
data, err := ws.Call("browser.pairing.status", map[string]any{})
if err != nil {
return err
}
printer.Print(unmarshalMap(data))
return nil
},
}
func init() {
devicesCmd.AddCommand(devicesListCmd, devicesRevokeCmd, devicesPairingStatusCmd)
rootCmd.AddCommand(devicesCmd)
}