diff --git a/packages/ess-migration-tool/newsfragments/1343.feature.md b/packages/ess-migration-tool/newsfragments/1343.feature.md new file mode 100644 index 00000000..b54d8fcc --- /dev/null +++ b/packages/ess-migration-tool/newsfragments/1343.feature.md @@ -0,0 +1 @@ +Use Rich library to display formatted tables for migration mappings, workers, secrets, and warnings in the CLI output. diff --git a/packages/ess-migration-tool/src/ess_migration_tool/__main__.py b/packages/ess-migration-tool/src/ess_migration_tool/__main__.py index 745b7413..e8c23fdf 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/__main__.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/__main__.py @@ -18,7 +18,7 @@ from .hookshot import HOOKSHOT_STRATEGY_NAME from .inputs import InputProcessor, ValidationError from .mas import MAS_STRATEGY_NAME, parse_postgres_uri from .outputs import generate_helm_values, write_outputs -from .rich_output import ProgressReporter, log_command, print_section, print_table +from .rich_output import ProgressReporter, log_command, print_section, print_separator, print_table from .synapse import SYNAPSE_STRATEGY_NAME from .utils import press_enter_to_continue, prompt_for_database_choice @@ -604,7 +604,7 @@ Examples: press_enter_to_continue(pretty_logger) - pretty_logger.info("=" * 60) + print_separator(logger=pretty_logger) reporter.report_success(args.output_dir) logging.info("Migration completed successfully!") diff --git a/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py b/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py index c825586d..3939d847 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/conflicts.py @@ -11,6 +11,7 @@ import logging from typing import Any from .models import DiscoveredSecretTracking, SecretSource, ValueSourceTracking +from .rich_output import print_separator from .utils import is_quiet_mode, prompt_choice, prompt_value, set_nested_value @@ -101,9 +102,9 @@ def resolve_secret_conflicts( logger = logging.getLogger("migration") pretty_logger.info("") - pretty_logger.info("=" * 60) + print_separator(logger=pretty_logger) pretty_logger.info("šŸ” RESOLVING SECRET CONFLICTS") - pretty_logger.info("=" * 60) + print_separator(logger=pretty_logger) pretty_logger.info("Some secrets were discovered by multiple strategies with different values.") pretty_logger.info("Please select which value to use for each:") pretty_logger.info("") @@ -144,4 +145,4 @@ def resolve_secret_conflicts( pretty_logger.info(f" āœ… Resolved {secret_key}") pretty_logger.info("") - pretty_logger.info("=" * 60) + print_separator(logger=pretty_logger) diff --git a/packages/ess-migration-tool/src/ess_migration_tool/extra_files.py b/packages/ess-migration-tool/src/ess_migration_tool/extra_files.py index 16de3477..888068d5 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/extra_files.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/extra_files.py @@ -15,7 +15,7 @@ from urllib.parse import urlparse from .interfaces import ExtraFilesDiscoveryStrategy, SecretDiscoveryStrategy from .models import DiscoverableSecret, DiscoveredExtraFile, DiscoveredPath -from .rich_output import print_section +from .rich_output import print_section, print_separator from .utils import is_quiet_mode, prompt_choice, prompt_value, prompt_yes_no logger = logging.getLogger("migration") @@ -377,7 +377,7 @@ class ExtraFilesDiscovery: if self.discovered_file_paths or self.discovered_extra_files: component_name = self.strategy.component_name self.pretty_logger.info(f"\nāœ… Extra files validation completed ({component_name})") - self.pretty_logger.info("=" * 60) + print_separator(logger=self.pretty_logger) def _is_binary_file(self, path: Path) -> bool: """ diff --git a/packages/ess-migration-tool/src/ess_migration_tool/rich_output.py b/packages/ess-migration-tool/src/ess_migration_tool/rich_output.py index 6ed3d6cf..8dc2dabd 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/rich_output.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/rich_output.py @@ -199,6 +199,28 @@ def print_prompt( get_console().print(styled) +def print_separator( + logger: logging.Logger | None = None, +) -> None: + """ + Print a separator line using Rich styling if available. + Uses terminal width when Rich is enabled, falls back to 60 for plain text. + + Args: + logger: Logger to use for fallback output when Rich is disabled + """ + if not is_rich_enabled(): + # Fallback to plain text using the provided logger + if logger is not None: + logger.info("=" * 60) + return + + # Rich is enabled - use a styled separator with terminal width + console = get_console() + separator = "─" * console.width + console.print(separator, style="cyan") + + class ProgressReporter: """ Handles progress reporting for the migration process. diff --git a/packages/ess-migration-tool/src/ess_migration_tool/secrets.py b/packages/ess-migration-tool/src/ess_migration_tool/secrets.py index 8405f15e..0cc83391 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/secrets.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/secrets.py @@ -11,7 +11,7 @@ from dataclasses import dataclass, field from .interfaces import SecretDiscoveryStrategy from .models import DiscoverableSecret, DiscoveredSecret, DiscoveredSecretTracking, GlobalOptions, SecretConfig -from .rich_output import print_section +from .rich_output import print_section, print_separator from .utils import ( find_matching_schema_key, get_nested_value, @@ -328,4 +328,4 @@ class SecretDiscovery: self.pretty_logger.info(f" āœ… Secret stored for {secret_key}") self.pretty_logger.info(f"\nāœ… All required {component_name} secrets have been provided") - self.pretty_logger.info("=" * 60) + print_separator(logger=self.pretty_logger) diff --git a/packages/ess-migration-tool/src/ess_migration_tool/utils.py b/packages/ess-migration-tool/src/ess_migration_tool/utils.py index c036a96b..3adbbf5a 100644 --- a/packages/ess-migration-tool/src/ess_migration_tool/utils.py +++ b/packages/ess-migration-tool/src/ess_migration_tool/utils.py @@ -18,7 +18,7 @@ from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import ec, rsa from .models import MigrationError -from .rich_output import get_console, is_rich_enabled, print_prompt, print_section +from .rich_output import is_rich_enabled, print_prompt, print_section def yaml_dump_with_pipe_for_multiline(data: Any) -> str: @@ -458,16 +458,33 @@ def prompt_for_database_choice(pretty_logger: logging.Logger) -> bool: True if user wants to use existing database, False for ESS-managed PostgreSQL """ print_section("šŸ—ƒļø DATABASE CONFIGURATION CHOICE", logger=pretty_logger) - print_prompt("How would you like to handle the database for your ESS deployment?", style="bold white", logger=pretty_logger, prefix="") + print_prompt( + "How would you like to handle the database for your ESS deployment?", + style="bold white", + logger=pretty_logger, + prefix="", + ) print("") - print_prompt("1. šŸ”— Connect to existing database (recommended for production)", style="bold cyan", logger=pretty_logger, prefix="") + print_prompt( + "1. šŸ”— Connect to existing database (recommended for production)", + style="bold cyan", + logger=pretty_logger, + prefix="", + ) print_prompt("- Import your current database settings into ESS", style="dim", logger=pretty_logger, prefix=" ") print_prompt("- Continue using your existing PostgreSQL instance", style="dim", logger=pretty_logger, prefix=" ") print("") - print_prompt("2. šŸ†• Install PostgreSQL with ESS and import database later", style="white", logger=pretty_logger, prefix="") + print_prompt( + "2. šŸ†• Install PostgreSQL with ESS and import database later", style="white", logger=pretty_logger, prefix="" + ) print_prompt("- Let ESS deploy and manage PostgreSQL", style="dim", logger=pretty_logger, prefix=" ") - print_prompt("- Import your Synapse and MAS database schemas after deployment", style="dim", logger=pretty_logger, prefix=" ") + print_prompt( + "- Import your Synapse and MAS database schemas after deployment", + style="dim", + logger=pretty_logger, + prefix=" ", + ) print("") choice = prompt_choice( @@ -481,7 +498,9 @@ def prompt_for_database_choice(pretty_logger: logging.Logger) -> bool: print_prompt("āœ… Using existing database configuration", style="bold green", logger=pretty_logger) return True else: - print_prompt("āœ… Using ESS-managed PostgreSQL (import database later)", style="bold green", logger=pretty_logger) + print_prompt( + "āœ… Using ESS-managed PostgreSQL (import database later)", style="bold green", logger=pretty_logger + ) return False