Skip to content

Commit 53bac53

Browse files
committed
History: Add new options --head, --tail, and --reverse
1 parent 8159e46 commit 53bac53

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ in progress
1212
- Refactoring: Move all report renderers to ``grafana_wtf.report``
1313
- History: Add ``id`` and ``uid`` dashboard attributes to report
1414
- History: Unlock YAML export format
15+
- History: Add new options ``--head``, ``--tail``, and ``--reverse``
1516

1617
2023-03-05 0.14.1
1718
=================

grafana_wtf/commands.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run():
3131
grafana-wtf [options] explore dashboards
3232
grafana-wtf [options] find [<search-expression>]
3333
grafana-wtf [options] replace <search-expression> <replacement> [--dry-run]
34-
grafana-wtf [options] log [<dashboard_uid>] [--number=<count>]
34+
grafana-wtf [options] log [<dashboard_uid>] [--number=<count>] [--head=<count>] [--tail=<count>] [--reverse]
3535
grafana-wtf --version
3636
grafana-wtf (-h | --help)
3737
@@ -221,11 +221,21 @@ def run():
221221

222222
if options.log:
223223
entries = engine.log(dashboard_uid=options.dashboard_uid)
224-
entries = sorted(entries, key=itemgetter("datetime"), reverse=True)
224+
entries = sorted(entries, key=itemgetter("datetime"))
225225

226226
if options.number is not None:
227-
count = int(options.number)
228-
entries = entries[:count]
227+
limit = int(options.number)
228+
entries = entries[-limit:]
229+
options.reverse = True
230+
elif options.tail is not None:
231+
limit = int(options.tail)
232+
entries = entries[-limit:]
233+
elif options.head is not None:
234+
limit = int(options.head)
235+
entries = entries[:limit]
236+
237+
if options.reverse:
238+
entries = list(reversed(entries))
229239

230240
if output_format.startswith("tabular"):
231241
report = TabularEditHistoryReport(data=entries)

0 commit comments

Comments
 (0)