-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
57 lines (47 loc) · 1.08 KB
/
cli.go
File metadata and controls
57 lines (47 loc) · 1.08 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
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/lyricalsoul/crystalline/seedlink"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: go run cli.go server:port")
return
}
server := os.Args[1]
splitted := strings.Split(server, ":")
if len(splitted) != 2 {
fmt.Println("Usage: go run cli.go server:port")
return
}
fmt.Printf("Connecting to server %s on port %s...\n", splitted[0], splitted[1])
client := seedlink.SeedLinkConnection{
URL: server,
PrintIncomingMessages: true,
}
if err := client.Connect(); err != nil {
fmt.Println("Error connecting to server:", err)
return
}
defer client.Disconnect()
fmt.Println("Crystalline Interactive Shell. Type 'exit' to quit.")
fmt.Print("> ")
scanner := bufio.NewScanner(os.Stdin)
for {
if !scanner.Scan() {
break
}
input := strings.ToUpper(scanner.Text())
if strings.TrimSpace(input) == "EXIT" {
fmt.Println("Exiting...")
client.SendRaw("BYE")
os.Exit(0)
}
if err := client.SendRaw(strings.TrimSpace(input)); err != nil {
fmt.Println("Error:", err)
}
}
}