Skip to content

interactive

appimage_updater.ui.interactive

Interactive mode utilities for AppImage Updater commands - Refactored for testability.

This module provides interactive prompts and guidance for commands that take parameters, making the CLI more user-friendly for new users. The refactored version uses dependency injection to make the code easily testable.

ConfirmInterface

Protocol for confirmation functionality.

ask(prompt, **kwargs) staticmethod

Ask for user confirmation.

Source code in src/appimage_updater/ui/interactive.py
@staticmethod
def ask(prompt: str, **kwargs: Any) -> bool:
    """Ask for user confirmation."""
    ...

IntPromptInterface

Protocol for integer prompt functionality.

ask(prompt, **kwargs) staticmethod

Ask for integer input.

Source code in src/appimage_updater/ui/interactive.py
@staticmethod
def ask(prompt: str, **kwargs: Any) -> int:
    """Ask for integer input."""
    ...

InteractiveAddHandler(console=None, prompt=None, confirm=None, int_prompt=None)

Handler for interactive add command with dependency injection.

Source code in src/appimage_updater/ui/interactive.py
def __init__(
    self,
    console: Console | None = None,
    prompt: PromptInterface | None = None,
    confirm: ConfirmInterface | None = None,
    int_prompt: IntPromptInterface | None = None,
) -> None:
    """Initialize with optional dependency injection for testing."""
    self.console = console or Console()
    self.prompt = prompt or Prompt
    self.confirm = confirm or Confirm
    self.int_prompt = int_prompt or IntPrompt

confirm = confirm or Confirm instance-attribute

console = console or Console() instance-attribute

int_prompt = int_prompt or IntPrompt instance-attribute

prompt = prompt or Prompt instance-attribute

interactive_add_command()

Interactive mode for the add command.

Source code in src/appimage_updater/ui/interactive.py
def interactive_add_command(self) -> InteractiveResult:
    """Interactive mode for the add command."""
    self._display_welcome_message()

    try:
        # Collect all settings through helper functions
        basic_settings = self._collect_basic_add_settings()
        rotation_settings = self._collect_rotation_add_settings(basic_settings["name"])
        checksum_settings = self._collect_checksum_add_settings()
        advanced_settings = self._collect_advanced_add_settings(basic_settings["url"])

        # Combine all settings
        all_settings = {**basic_settings, **rotation_settings, **checksum_settings, **advanced_settings}

        # Display summary and confirm
        self._display_add_summary(all_settings)

        if not self.confirm.ask("\nAdd this application?", default=True):
            self.console.print("[yellow]Operation cancelled[/yellow]")
            return InteractiveResult.cancelled_result("user_cancelled")

        return InteractiveResult.success_result(all_settings)

    except KeyboardInterrupt:
        self.console.print("\n[yellow]Operation cancelled[/yellow]")
        return InteractiveResult.cancelled_result("keyboard_interrupt")

PromptInterface

Protocol for prompt functionality.

ask(prompt, **kwargs) staticmethod

Ask for user input.

Source code in src/appimage_updater/ui/interactive.py
@staticmethod
def ask(prompt: str, **kwargs: Any) -> str:
    """Ask for user input."""
    ...

interactive_add_command()

Interactive mode for the add command - backward compatibility wrapper.

Source code in src/appimage_updater/ui/interactive.py
def interactive_add_command() -> InteractiveResult:
    """Interactive mode for the add command - backward compatibility wrapper."""
    handler = InteractiveAddHandler()
    return handler.interactive_add_command()