Draft: feat: add categories command to list available categories
Add categories command to list available upload categories
Overview
This Merge Request introduces the corpus-client categories command to the CLI. It allows authenticated users to fetch and view a live list of available upload categories directly from the terminal.
Why is this necessary? (Motivation)
Before this feature, users had no way to know which categories were valid for file uploads without leaving the terminal to check the web application. Because the backend API requires exact Category IDs (UUIDs) to process uploads successfully, users were forced to guess or manually look up these strings.
This command solves that Developer Experience (DX) friction by acting as a built-in reference menu. It keeps users in their terminal workflow and prevents upload errors caused by invalid category inputs.
Changes Made
Modified File: src/corpus_client_cli/cli.py
-
Command Registration: Added the
categoriesfunction using Typer's@app.command()decorator to map it to the CLI interface. - Authentication Check: Implemented state validation to verify the user has an active session token before attempting the network request.
-
API Integration: Built an asynchronous HTTP GET request using
aiohttpto fetch data from the/api/v1/categories/endpoint. - Data Handling: Added defensive parsing to safely extract the category data, regardless of minor variations in the JSON payload structure.
-
Terminal UI: Integrated the
richlibrary to transform the raw JSON response into a clean, formatted table displaying both the Category ID and Name.
How to Test
- Ensure your virtual environment is active.
- Authenticate the CLI (if not already logged in):
uv run corpus-client login - Execute the new command:
uv run corpus-client categories - Verify that a formatted table containing the categories and their IDs renders successfully in the console.