Skip to content

Commit febed56

Browse files
committed
Improve output of find subcommand wrt. global/non-panel matches
1 parent a7bcedb commit febed56

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

grafana_wtf/report.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,52 @@ def output_items(self, label, items, url_callback):
6060
if bibdata_output:
6161
print(bibdata_output)
6262

63-
# Output findings.
63+
# Separate matches into "dashboard"- and "panels"-groups.
64+
dashboard_matches = []
65+
panel_matches = []
6466
if "matches" in item.meta:
6567
# print(' ', self.format_where(item))
66-
seen = {}
6768
for match in item.meta.matches:
6869
panel = self.get_panel(match)
69-
if panel is not None and panel.id not in seen:
70-
seen[panel.id] = True
71-
print()
70+
if panel is not None:
71+
panel_matches.append((match, panel))
72+
else:
73+
dashboard_matches.append(match)
7274

73-
title = panel.title
74-
subsection = f"Panel »{title}«"
75-
print(_ss(subsection))
76-
print("-" * len(subsection))
77-
78-
print(self.get_bibdata_panel(panel, url))
79-
print(" Matches")
80-
match = "- {path}: {value}".format(path=_k(match.full_path), value=_m(str(match.value).strip()))
81-
print(textwrap.indent(match, " " * 14))
75+
# Output dashboard matches.
76+
print()
77+
subsection = f"Global"
78+
print(_ss(subsection))
79+
print("-" * len(subsection))
80+
for match in dashboard_matches:
81+
match_text = f"- {self.format_match(match)}"
82+
print(match_text)
83+
84+
# Output panel bibdata with matches.
85+
seen = {}
86+
for match, panel in panel_matches:
87+
if panel.id not in seen:
88+
seen[panel.id] = True
89+
print()
90+
91+
title = panel.title
92+
subsection = f"Panel »{title}«"
93+
print(_ss(subsection))
94+
print("-" * len(subsection))
95+
96+
print(self.get_bibdata_panel(panel, url))
97+
print(" Matches")
98+
99+
match_text = f"- {self.format_match(match)}"
100+
print(textwrap.indent(match_text, " " * 14))
82101

83102
print()
84103
print()
85104

105+
@staticmethod
106+
def format_match(match):
107+
return "{path}: {value}".format(path=_k(match.full_path), value=_m(str(match.value).strip()))
108+
86109
def get_panel(self, node):
87110
"""
88111
Find panel from jsonpath node.

0 commit comments

Comments
 (0)