CLI Utilities

CLI utilities and business logic.

This module contains business logic that was in the CLI but should be in the library for better separation of concerns.

simulchip.cli_utils.resolve_collection_path(collection_file)[source]

Resolve collection file path with default fallback.

Parameters:

collection_file (Optional[Path]) – Optional collection file path

Return type:

Path

Returns:

Resolved collection file path

simulchip.cli_utils.ensure_collection_directory(collection_file)[source]

Ensure collection file directory exists.

Parameters:

collection_file (Path) – Path to collection file

Return type:

None

simulchip.cli_utils.ensure_output_directory(output_path)[source]

Ensure output directory exists.

Parameters:

output_path (Path) – Path to output file

Return type:

None

simulchip.cli_utils.validate_collection_exists(collection_file)[source]

Check if collection file exists.

Parameters:

collection_file (Path) – Path to collection file

Return type:

bool

Returns:

True if collection file exists and is a file (not a directory)

simulchip.cli_utils.should_generate_proxies(proxy_cards)[source]

Determine if proxy generation should proceed.

Parameters:

proxy_cards (List[Any]) – List of cards to generate proxies for

Return type:

bool

Returns:

True if proxy generation should proceed

simulchip.cli_utils.get_proxy_generation_message(proxy_cards, all_cards)[source]

Get appropriate message for proxy generation.

Parameters:
  • proxy_cards (List[Any]) – List of cards to generate proxies for

  • all_cards (bool) – Whether generating all cards or just missing

Return type:

str

Returns:

Formatted message string

simulchip.cli_utils.filter_valid_packs(packs)[source]

Filter packs to only include valid ones (have code and name).

Parameters:

packs (List[Dict[str, Any]]) – List of pack data dictionaries

Return type:

List[Dict[str, Any]]

Returns:

List of valid pack data dictionaries

simulchip.cli_utils.calculate_collection_stats(owned_packs, all_packs)[source]

Calculate collection statistics.

Parameters:
  • owned_packs (set) – Set of owned pack codes

  • all_packs (List[Dict[str, Any]]) – List of all pack data

Return type:

Dict[str, int]

Returns:

Dictionary with collection statistics

simulchip.cli_utils.validate_pack_selection(choice_str, max_choices)[source]

Validate pack selection input.

Parameters:
  • choice_str (str) – User input string

  • max_choices (int) – Maximum valid choice number

Return type:

Tuple[bool, Optional[int]]

Returns:

Tuple of (is_valid, choice_number or None)

simulchip.cli_utils.get_navigation_page_size()[source]

Get page size for navigation operations.

Return type:

int

Returns:

Page size for pagination

simulchip.cli_utils.calculate_selection_bounds(current_idx, total_items, operation='none')[source]

Calculate new selection index within bounds.

Parameters:
  • current_idx (int) – Current selection index

  • total_items (int) – Total number of items

  • operation (str) – Type of operation (‘up’, ‘down’, ‘page_up’, ‘page_down’, ‘top’, ‘bottom’)

Return type:

int

Returns:

New selection index within bounds

simulchip.cli_utils.should_reset_selection_on_filter_change()[source]

Determine if selection should reset when filter changes.

Return type:

bool

Returns:

True if selection should reset to 0 when filter changes

simulchip.cli_utils.get_card_quantity_action(key)[source]

Map keyboard input to card quantity action.

Parameters:

key (str) – Keyboard input key

Return type:

Tuple[str, int]

Returns:

Tuple of (action_type, value) where action_type is ‘increment’, ‘decrement’, ‘set’, or ‘none’

simulchip.cli_utils.should_ignore_pack_toggle_errors()[source]

Determine if pack toggle errors should be silently ignored.

Return type:

bool

Returns:

True if pack toggle errors should be ignored (for better UX)

class simulchip.cli_utils.NavigationConfig[source]

Bases: object

Configuration for navigation behavior.

__init__()[source]

Initialize navigation configuration with defaults.

Return type:

None

get_viewport_padding(interface_type)[source]

Get viewport padding for interface type.

Parameters:

interface_type (str) – Type of interface

Return type:

int

Returns:

Number of lines to reserve for UI elements