liveBook · Manning

Bark

As explained in Practices of the Python Pro

Bark is a book-specific command-line bookmarking application for creating, listing, and deleting saved bookmarks.

Bark is a command-line bookmarking application for creating, listing, and deleting bookmarks. Each bookmark stores an ID, title, URL, optional notes, and a date-added timestamp. section 6.2

The application separates presentation, business logic, and persistence. A terminal menu triggers commands, while the database stores bookmark data; each layer knows only enough about its surroundings to perform its job. section 6.3.3 section 11.5.1

The interactive workflow follows a small, repeatable cycle:

  • Clear the terminal and print actions such as adding, listing by date or title, deleting, and quitting. section 6.3.3
  • Validate the user's choice, gather required bookmark fields, and allow notes to remain optional. section 6.3.3
  • Execute the selected command, display its result, wait for Enter, and return to the menu. section 6.3.3
  • Initialize the bookmarks table before entering the loop, creating the database file when necessary. section 6.3.3

A menu option connects interface and behavior

An add option pairs the label "Add a bookmark" with an AddBookmarkCommand and a preparation function that collects title, URL, and notes. The menu handles interaction; the command handles the requested operation. section 6.3.3

Listing 6.11. Connecting menu text to business logic commands
class Option:
    def __init__(self, name, command, prep_call=None):
        self.name = name                                     #1
        self.command = command                               #2
        self.prep_call = prep_call                           #3


    def choose(self):                                        #4
        data = self.prep_call() if self.prep_call else None  #5
        message = self.command.execute(data) if data
else self.command.execute()                                #6
        print(message)

    def __str__(self):                                       #7
        return self.name

Inspect the compact Option class to see how menu labels, input preparation, command execution, and result printing are kept together without placing business logic in the interface. section 6.3.3

How Practices of the Python Pro covers it

How deep it goes
Descends through menu handling, input validation, command dispatch, looping, and database initialization, but defers bookmark updates.
Examples
Demonstrates menu options, bookmark prompts, command objects, a repeating CLI loop, and automatic bookmarks-table creation.
What you can do after
Build and extend a layered Python bookmarking CLI while adding features or tests without tightly coupling its interface and storage.
How it connects
Connects command-line interfaces, separation of concerns, multitier architecture, business logic, persistence, interfaces, and the command pattern.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.