Skip to content

command

appimage_updater.config.command

Configuration management command implementation.

console = Console(no_color=(bool(os.environ.get('NO_COLOR', '')))) module-attribute

logger = logging.getLogger(__name__) module-attribute

list_settings(config_file=None, config_dir=None)

List all available configuration settings with descriptions.

Source code in src/appimage_updater/config/command.py
def list_settings(config_file: Path | None = None, config_dir: Path | None = None) -> None:
    """List all available configuration settings with descriptions."""
    formatter = get_output_formatter()

    if formatter and not hasattr(formatter, "console"):
        # For structured formats (markdown, plain, json, html)
        _list_settings_structured(formatter)
    else:
        # For console formats, use the rich formatting with the formatter's console
        if formatter and hasattr(formatter, "console"):
            _list_settings_console(formatter.console)
        else:
            _list_settings_console(console)

reset_global_config(config_file=None, config_dir=None)

Reset global configuration to defaults.

Returns:

Type Description
bool

True if successful, False if error occurred

Source code in src/appimage_updater/config/command.py
def reset_global_config(config_file: Path | None = None, config_dir: Path | None = None) -> bool:
    """Reset global configuration to defaults.

    Returns:
        True if successful, False if error occurred
    """
    try:
        app_configs = AppConfigs(config_path=config_file or config_dir)
        config = app_configs._config
    except ConfigLoadError:
        console.print("[yellow]No existing configuration found. Nothing to reset.")
        return False

    # Reset to defaults
    config.global_config = GlobalConfig()

    console.print("[green]Configuration saved successfully!")

    # Save the updated configuration
    _save_config(config, config_file, config_dir)
    return True

set_global_config_value(setting, value, config_file=None, config_dir=None, global_manager_factory=GlobalConfigManager)

Set a global configuration value.

Returns:

Type Description
bool

True if the setting was applied successfully, False otherwise.

Source code in src/appimage_updater/config/command.py
def set_global_config_value(
    setting: str,
    value: str,
    config_file: Path | None = None,
    config_dir: Path | None = None,
    global_manager_factory: Any = GlobalConfigManager,
) -> bool:
    """Set a global configuration value.

    Returns:
        True if the setting was applied successfully, False otherwise.
    """
    target_path = config_file or config_dir
    global_manager = global_manager_factory(target_path)
    config = global_manager.config

    # Apply the setting change
    if not _apply_setting_change(config, setting, value):
        return False  # Error already displayed

    # Save the updated configuration
    _save_config(config, config_file, config_dir)
    return True

show_effective_config(app_name, config_file=None, config_dir=None, app_configs_factory=AppConfigs, formatter_factory=get_output_formatter)

Show effective configuration for a specific application.

The additional parameters are primarily for testing, allowing injection of factories for configuration loading and output formatting without touching the actual file system or global formatter state.

Source code in src/appimage_updater/config/command.py
def show_effective_config(
    app_name: str,
    config_file: Path | None = None,
    config_dir: Path | None = None,
    app_configs_factory: Any = AppConfigs,
    formatter_factory: Callable[[], Any] = get_output_formatter,
) -> None:
    """Show effective configuration for a specific application.

    The additional parameters are primarily for testing, allowing injection of
    factories for configuration loading and output formatting without touching
    the actual file system or global formatter state.
    """
    try:
        config_path = config_file or config_dir
        app_configs = app_configs_factory(config_path)
        config = app_configs._config
        effective_config = config.get_effective_config_for_app(app_name)

        if effective_config is None:
            _handle_app_not_found(app_name)
            return

        _display_effective_config(app_name, effective_config, formatter_factory)

    except ConfigLoadError as e:
        _handle_config_load_error(e)

show_global_config(config_file=None, config_dir=None, app_configs_factory=AppConfigs, formatter_factory=get_output_formatter)

Show current global configuration.

The additional parameters are primarily for testing, allowing injection of factories for configuration loading and output formatting without touching the actual file system or global formatter state.

Source code in src/appimage_updater/config/command.py
def show_global_config(
    config_file: Path | None = None,
    config_dir: Path | None = None,
    app_configs_factory: Any = AppConfigs,
    formatter_factory: Callable[[], Any] = get_output_formatter,
) -> None:
    """Show current global configuration.

    The additional parameters are primarily for testing, allowing injection of
    factories for configuration loading and output formatting without touching
    the actual file system or global formatter state.
    """
    try:
        config_path = config_file or config_dir
        app_configs = app_configs_factory(config_path)
        config = app_configs._config
        defaults = config.global_config.defaults
        output_formatter = formatter_factory()

        if output_formatter and not hasattr(output_formatter, "console"):
            _print_global_config_structured(config.global_config, defaults, output_formatter)
        else:
            _print_global_config_rich(config.global_config, defaults, output_formatter)

    except ConfigLoadError as e:
        _handle_config_load_error(e)

update_config_from_defaults(config_file=None, config_dir=None, app_configs_factory=AppConfigs, manager_factory=Manager)

Rewrite configuration files based on current global defaults.

This action reloads the full directory-based configuration (global + applications) and then saves it back out using the same directory-based serializer used by edit --update. The primary purpose is to ensure that all application configs and the global config reflect the latest default path rules (e.g. relative paths, home-shortened globals).

Source code in src/appimage_updater/config/command.py
def update_config_from_defaults(
    config_file: Path | None = None,
    config_dir: Path | None = None,
    app_configs_factory: Any = AppConfigs,
    manager_factory: Any = Manager,
) -> bool:
    """Rewrite configuration files based on current global defaults.

    This action reloads the full directory-based configuration (global +
    applications) and then saves it back out using the same directory-based
    serializer used by edit --update. The primary purpose is to ensure that
    all application configs and the global config reflect the latest default
    path rules (e.g. relative paths, home-shortened globals).
    """

    try:
        # Determine the apps directory used for directory-based configs.
        apps_dir = config_dir or GlobalConfigManager.get_default_config_dir()

        # Load the current configuration (global + applications) using the
        # directory-based layout rooted at apps_dir.
        app_configs = app_configs_factory(apps_dir)
        config: Config = app_configs._config

        # Use the same manager used by EditCommand._save_config to persist the
        # directory-based configuration, including rewriting config.json and
        # apps/*.json with the latest serialization rules.
        manager: Manager = manager_factory()
        manager.save_directory_config(config, apps_dir)

        return True

    except ConfigLoadError as e:
        _handle_config_load_error(e)
        return False