clan-core/pkgs/clan-cli/clan_cli/history/list.py

27 lines
849 B
Python
Raw Normal View History

2023-12-11 18:09:34 +00:00
# !/usr/bin/env python3
import argparse
from datetime import datetime
2023-12-11 18:09:34 +00:00
from .add import HistoryEntry, list_history
2023-12-11 18:09:34 +00:00
def list_history_command(args: argparse.Namespace) -> None:
res: dict[str, list[HistoryEntry]] = {}
2023-12-11 18:09:34 +00:00
for history_entry in list_history():
url = str(history_entry.flake.flake_url)
if res.get(url, None) is None:
res[url] = []
res[url].append(history_entry)
for flake_url, entries in res.items():
print(flake_url)
for entry in entries:
d = datetime.fromisoformat(entry.last_used)
last_used = d.strftime("%d/%m/%Y %H:%M:%S")
print(f" {entry.flake.flake_attr} ({last_used})")
2023-12-11 18:09:34 +00:00
# takes a (sub)parser and configures it
def register_list_parser(parser: argparse.ArgumentParser) -> None:
parser.set_defaults(func=list_history_command)