From ec60a3d50672685f37c6c3d9018fff213a961f88 Mon Sep 17 00:00:00 2001 From: ppom <> Date: Thu, 4 Jan 2024 12:00:00 +0100 Subject: [PATCH] reaction show: remove empty patterns fix #64 --- app/client.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/client.go b/app/client.go index b3e0e6b..8be7bdb 100644 --- a/app/client.go +++ b/app/client.go @@ -89,6 +89,24 @@ func ClientShow(format, stream, filter string, regex *regexp.Regexp) { if response.Err != nil { logger.Fatalln("Received error from daemon:", response.Err) } + + // Remove empty structs + for streamName := range response.ClientStatus { + for filterName := range response.ClientStatus[streamName] { + for patternName, patternMap := range response.ClientStatus[streamName][filterName] { + if len(patternMap.Actions) == 0 && patternMap.Matches == 0 { + delete(response.ClientStatus[streamName][filterName], patternName) + } + } + if len(response.ClientStatus[streamName][filterName]) == 0 { + delete(response.ClientStatus[streamName], filterName) + } + } + if len(response.ClientStatus[streamName]) == 0 { + delete(response.ClientStatus, streamName) + } + } + // Limit to stream, filter if exists if stream != "" { exists := false @@ -114,6 +132,7 @@ func ClientShow(format, stream, filter string, regex *regexp.Regexp) { os.Exit(1) } } + // Limit to pattern if regex != nil { for streamName := range response.ClientStatus { @@ -132,6 +151,7 @@ func ClientShow(format, stream, filter string, regex *regexp.Regexp) { } } } + var text []byte var err error if format == "json" {