Misc cli changes #1

Merged
oysteikt merged 5 commits from misc-cli-changes into main 2024-05-17 23:06:35 +02:00
1 changed files with 4 additions and 3 deletions
Showing only changes of commit a53f83589d - Show all commits

View File

@ -13,6 +13,7 @@ class SearchCli(NumberedCmd):
def __init__(self, sql_session: Session): def __init__(self, sql_session: Session):
super().__init__() super().__init__()
self.sql_session = sql_session self.sql_session = sql_session
self.result = None
def do_search_all(self, _: str): def do_search_all(self, _: str):
@ -57,11 +58,11 @@ class SearchCli(NumberedCmd):
elif len(author) == 1: elif len(author) == 1:
selected_author = author[0] selected_author = author[0]
print('Found author:') print('Found author:')
print(f" {selected_author.name} ({sum(item.amount for item in selected_author.books)} items)") print(f" {selected_author.name} ({sum(item.amount for item in selected_author.items)} items)")
else: else:
selector = NumberedItemSelector( selector = NumberedItemSelector(
items = author, items = author,
stringify = lambda author: f"{author.name} ({sum(item.amount for item in author.books)} items)", stringify = lambda author: f"{author.name} ({sum(item.amount for item in author.items)} items)",
) )
selector.cmdloop() selector.cmdloop()
if selector.result is None: if selector.result is None:
@ -69,7 +70,7 @@ class SearchCli(NumberedCmd):
selected_author = selector.result selected_author = selector.result
selector = NumberedItemSelector( selector = NumberedItemSelector(
items = selected_author.books, items = list(selected_author.items),
stringify = lambda item: f"{item.name} ({item.isbn})", stringify = lambda item: f"{item.name} ({item.isbn})",
) )
selector.cmdloop() selector.cmdloop()