Capstone: A Persistent Lending Tool · practice
Print the Available Items
An available-items command should present the public query result, not create a second version of the query. The database boundary already decides which items are available and returns them in asset-tag order. available_command only owns the path, connection, and text table.
In the coherent demo, item 1 is active when this call runs:
main(["available", str(database_path)])
Add available_command(args). Its namespace has only args.database besides the command name. Refuse a missing path, then call prepare_database to verify or migrate the existing file. Open the application connection and call list_available_items(connection) exactly once. Store the returned finally.
Do not add SQL, another query, or id, asset_tag, name, category, and loan_days. The list already has the public order established by the database boundary.
Only after the query succeeds and the connection closes, print this fixed header:
id | asset_tag | name | category | loan_days
Then use a for | between values. An empty result still prints the header and returns 0. It is a successful answer to the question, not an application failure.
The command catches documented
Add the exact branch if args.command == "available": return available_command(args) to main, then press Run:
== available ==
Status: 0
id | asset_tag | name | category | loan_days
3 | EL-300 | Projector | electronics | 3
2 | EV-200 | Folding table | events | 14
stderr: <empty>
Notice that the rows are ordered by asset tag: EL-300 precedes EV-200, even though item 3 was inserted after item 2. That order comes directly from list_available_items. A thorough check supplies unseen Unicode and space-containing values, an active item, and a deliberately different insertion order. It also checks an empty catalog, connection closure, and the absence of writes.
Task
Add or complete available_command(args) and add this branch in main:
if args.command == "available":
return available_command(args)
Refuse a missing database, prepare and open it, call list_available_items exactly once, and close the application connection in finally. Print the exact five-column header and one pipe-delimited row per returned 0 on an empty or nonempty result.