Listing entries
Let us now focus on listing all the entries that are stored in the addressbook.db
file. We will first start with the business logic and we will then go to the CLI part of the application.
The business logic
The job left for the CLI to be completed is rather small. We only need to read data from the database and display it on the standard output. Let us start by reading the data from the database:
def list_contacts(db: IO[bytes]): book = read_from_db(db) #...
Next, we can order the list of contacts alphabetically. This was mostly done for testing purposes, but it could be used for more advanced features such as filtering or paging. Here, we will simply focus on displaying all the contacts. The sorting looks like the following:
def list_contacts(db: IO[bytes]): book = read_from_db(db) for name in sorted(book.contacts.keys()): #...
Now that we have sorted names, we can just display...