paper_firehose.core.command_context

Command context for shared initialization across CLI commands.

Provides a unified way to initialize config, database, and common parameters to reduce boilerplate code in command implementations.

Classes

CommandContext([config_path])

Encapsulates shared initialization logic for CLI commands.

class paper_firehose.core.command_context.CommandContext(config_path=None)[source]

Bases: object

Encapsulates shared initialization logic for CLI commands.

Handles config loading, validation, database connection, and topic resolution in a single reusable class to reduce boilerplate across commands.

Example

```python ctx = CommandContext(config_path) for topic in ctx.get_topics(topic_arg):

# Access ctx.config_manager, ctx.config, ctx.db entries = ctx.db.get_current_entries(topic=topic)

```

Parameters:

config_path (Optional[str])

get_default(key, default=None)[source]

Get value from defaults section of config.

Parameters:
  • key (str) – Config key (e.g., ‘rank_threshold’)

  • default (Any) – Fallback value if key not found

Return type:

Any

Returns:

Config value or default

get_nested_default(*keys, default=None)[source]

Get nested value from defaults section.

Parameters:
  • *keys (str) – Nested keys (e.g., ‘abstracts’, ‘mailto’)

  • default (Any) – Fallback value if path not found

Return type:

Any

Returns:

Config value or default

Example

`python # Get config.defaults.abstracts.mailto mailto = ctx.get_nested_default('abstracts', 'mailto', default='noreply@example.com') `

get_topics(topic=None)[source]

Resolve topic argument to list of topics to process.

Parameters:

topic (Optional[str]) – Optional single topic name, or None for all topics

Return type:

list[str]

Returns:

List of topic names (single topic or all available topics)

load_topic_config(topic)[source]

Load configuration for a specific topic.

Parameters:

topic (str) – Topic name

Return type:

Dict[str, Any]

Returns:

Topic configuration dictionary

Raises:

FileNotFoundError – If topic config file doesn’t exist