From 88fb5ace297af7f98e672fcce59018d133427972 Mon Sep 17 00:00:00 2001 From: Rushil Patel Date: Wed, 17 Sep 2025 14:17:39 -0700 Subject: [PATCH 1/2] fix: update prompt for auto update --- src/codegen/cli/cli.py | 8 ++++---- src/codegen/cli/commands/update/main.py | 3 ++- src/codegen/cli/commands/update/updater.py | 24 ++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/codegen/cli/cli.py b/src/codegen/cli/cli.py index 7de7fc85b..0ae7a9657 100644 --- a/src/codegen/cli/cli.py +++ b/src/codegen/cli/cli.py @@ -61,12 +61,12 @@ def version_callback(value: bool): # Check for updates on startup (non-blocking) try: - from codegen.cli.commands.update import check_for_updates_on_startup - - # Only check on actual command runs, not completions + # Only check when no arguments are passed (just "codegen" to launch TUI) import sys - if not any(arg in sys.argv for arg in ["--help", "-h", "completion", "--version"]): + from codegen.cli.commands.update import check_for_updates_on_startup + + if len(sys.argv) == 1: check_for_updates_on_startup() except ImportError: pass # Update check dependencies not available diff --git a/src/codegen/cli/commands/update/main.py b/src/codegen/cli/commands/update/main.py index 1cdd5d349..0a2a686d7 100644 --- a/src/codegen/cli/commands/update/main.py +++ b/src/codegen/cli/commands/update/main.py @@ -9,7 +9,8 @@ from rich.console import Console import codegen -from .updater import UpdateManager, check_for_updates_on_startup + +from .updater import UpdateManager console = Console() diff --git a/src/codegen/cli/commands/update/updater.py b/src/codegen/cli/commands/update/updater.py index 2987d9023..8edc7a61d 100644 --- a/src/codegen/cli/commands/update/updater.py +++ b/src/codegen/cli/commands/update/updater.py @@ -23,7 +23,7 @@ # Update configuration UPDATE_CHECK_FILE = Path.home() / ".codegen" / "update_check.json" -UPDATE_CHECK_INTERVAL = timedelta(hours=24) # Check for updates once per day +UPDATE_CHECK_INTERVAL = timedelta(hours=12) # Check for updates once per day class InstallMethod(Enum): @@ -219,7 +219,7 @@ def _save_last_check_time(self) -> None: with open(UPDATE_CHECK_FILE, "w") as f: json.dump({"last_check": datetime.now().isoformat()}, f) - def perform_update(self, target_version: Optional[str] = None, dry_run: bool = False) -> bool: + def perform_update(self, target_version: Optional[str] = None, dry_run: bool = False, skip_confirmation: bool = False) -> bool: """Perform the update to a specific version or latest.""" current_version = self._get_current_version() @@ -248,8 +248,8 @@ def perform_update(self, target_version: Optional[str] = None, dry_run: bool = F if dry_run: return True - # Confirm update - if not self._confirm_update(): + # Confirm update (skip if already confirmed) + if not skip_confirmation and not self._confirm_update(): self.console.print("[yellow]Update cancelled[/yellow]") return False @@ -382,15 +382,23 @@ def _update_via_homebrew(self, target: Version) -> bool: def check_for_updates_on_startup() -> None: - """Check for updates on CLI startup (non-blocking).""" + """Check for updates on CLI startup with blocking prompt.""" try: # Only check if we haven't checked recently manager = UpdateManager() - result = manager.check_for_updates(force=False) + result = manager.check_for_updates(force=True) if result.update_available: - console.print(f"\n[cyan]ℹ️ A new version of Codegen CLI is available: {result.latest_version}[/cyan]") - console.print("[dim]Run 'codegen update' to upgrade[/dim]\n") + console.print(f"\n[cyan]ℹ️ A new version of Codegen CLI is available: {result.current_version} → {result.latest_version}[/cyan]") + + if manager.perform_update(): + console.print("\n[green]✓ Update completed successfully![/green]") + console.print("[yellow]Please restart your terminal or run a new codegen command to use the updated version.[/yellow]\n") + # Exit after successful update + sys.exit(0) + else: + console.print("\n[red]Update failed. Please try running 'codegen update' manually.[/red]\n") + except Exception: # Silently ignore update check failures on startup pass From 388e8ee604fdf6c7aabbf7ae31e781f036229a88 Mon Sep 17 00:00:00 2001 From: Rushil Patel Date: Wed, 17 Sep 2025 14:36:54 -0700 Subject: [PATCH 2/2] fix: on update command force check --- src/codegen/cli/commands/update/main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/codegen/cli/commands/update/main.py b/src/codegen/cli/commands/update/main.py index 0a2a686d7..56430c5da 100644 --- a/src/codegen/cli/commands/update/main.py +++ b/src/codegen/cli/commands/update/main.py @@ -39,8 +39,6 @@ def update( list_: bool = typer.Option(False, "--list", "-l", help="List all supported versions"), version: str | None = typer.Option(None, "--version", "-v", help="Update to a specific version"), check: bool = typer.Option(False, "--check", help="Check for available updates without installing"), - dry_run: bool = typer.Option(False, "--dry-run", help="Show what would be updated without making changes"), - force: bool = typer.Option(False, "--force", "-f", help="Force update check even if recently checked"), legacy: bool = typer.Option(False, "--legacy", help="Use legacy update method (simple pip upgrade)"), ): """Update Codegen CLI to the latest or specified version. @@ -61,7 +59,7 @@ def update( # Handle different actions if check or list_: - result = manager.check_for_updates(force=force) + result = manager.check_for_updates(force=True) if result.update_available: console.print(f"\n[cyan]Update available: {result.current_version} → {result.latest_version}[/cyan]")