- commit
- 56ae22e
- parent
- 03091f8
- author
- Antonio Mika
- date
- 2024-10-02 23:03:21 +0000 UTC
Simplify ls
1 files changed,
+17,
-18
+17,
-18
1@@ -68,6 +68,20 @@ func toPublicChannel(name string) string {
2 return fmt.Sprintf("public/%s", name)
3 }
4
5+func clientInfo(clients []*psub.Client, clientType string) string {
6+ if len(clients) == 0 {
7+ return ""
8+ }
9+
10+ outputData := fmt.Sprintf("\t%s:\r\n", clientType)
11+
12+ for _, client := range clients {
13+ outputData += fmt.Sprintf("\t- %s:\r\n", client.ID)
14+ }
15+
16+ return outputData
17+}
18+
19 var helpStr = `Commands: [pub, sub, ls, pipe]
20
21 The simplest authenticated pubsub system. Send messages through
22@@ -158,24 +172,9 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
23 pipes = append(pipes, client)
24 }
25 }
26-
27- outputData += "\tPubs:\r\n"
28-
29- for _, pub := range pubs {
30- outputData += fmt.Sprintf("\t- %s:\r\n", pub.ID)
31- }
32-
33- outputData += "\tSubs:\r\n"
34-
35- for _, sub := range subs {
36- outputData += fmt.Sprintf("\t- %s:\r\n", sub.ID)
37- }
38-
39- outputData += "\tPipes:\r\n"
40-
41- for _, pipe := range pipes {
42- outputData += fmt.Sprintf("\t- %s:\r\n", pipe.ID)
43- }
44+ outputData += clientInfo(pubs, "Pubs")
45+ outputData += clientInfo(subs, "Subs")
46+ outputData += clientInfo(pipes, "Pipes")
47 }
48 }
49