-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_focus.go
More file actions
52 lines (44 loc) · 1.38 KB
/
cmd_focus.go
File metadata and controls
52 lines (44 loc) · 1.38 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
package main
import "github.com/spf13/cobra"
func focusCmd() *cobra.Command {
var chatID, messageID, draftText, draftAttachment string
cmd := &cobra.Command{
Use: "focus",
Short: "Focus the Beeper Desktop app window",
Long: `Focus the Beeper Desktop app window and optionally open a chat.
Examples:
beeper focus
beeper focus --chat-id "!abc123:beeper.local"
beeper focus --chat-id "!abc123:beeper.local" --draft-text "Hello!"`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := getClient()
if err != nil {
return err
}
body := map[string]interface{}{}
if chatID != "" {
body["chatID"] = cleanID(chatID)
}
if messageID != "" {
body["messageID"] = cleanID(messageID)
}
if draftText != "" {
body["draftText"] = draftText
}
if draftAttachment != "" {
body["draftAttachmentPath"] = draftAttachment
}
result, err := client.request("POST", "/v1/focus", nil, body)
if err != nil {
return err
}
outputResult(result)
return nil
},
}
cmd.Flags().StringVarP(&chatID, "chat-id", "c", "", "Chat ID to focus")
cmd.Flags().StringVarP(&messageID, "message-id", "m", "", "Message ID to jump to")
cmd.Flags().StringVarP(&draftText, "draft-text", "d", "", "Text to pre-fill in message input")
cmd.Flags().StringVar(&draftAttachment, "draft-attachment", "", "File path for draft attachment")
return cmd
}