|
23 | 23 |
|
24 | 24 | # Update configuration |
25 | 25 | UPDATE_CHECK_FILE = Path.home() / ".codegen" / "update_check.json" |
26 | | -UPDATE_CHECK_INTERVAL = timedelta(hours=24) # Check for updates once per day |
| 26 | +UPDATE_CHECK_INTERVAL = timedelta(hours=12) # Check for updates once per day |
27 | 27 |
|
28 | 28 |
|
29 | 29 | class InstallMethod(Enum): |
@@ -219,7 +219,7 @@ def _save_last_check_time(self) -> None: |
219 | 219 | with open(UPDATE_CHECK_FILE, "w") as f: |
220 | 220 | json.dump({"last_check": datetime.now().isoformat()}, f) |
221 | 221 |
|
222 | | - def perform_update(self, target_version: Optional[str] = None, dry_run: bool = False) -> bool: |
| 222 | + def perform_update(self, target_version: Optional[str] = None, dry_run: bool = False, skip_confirmation: bool = False) -> bool: |
223 | 223 | """Perform the update to a specific version or latest.""" |
224 | 224 | current_version = self._get_current_version() |
225 | 225 |
|
@@ -248,8 +248,8 @@ def perform_update(self, target_version: Optional[str] = None, dry_run: bool = F |
248 | 248 | if dry_run: |
249 | 249 | return True |
250 | 250 |
|
251 | | - # Confirm update |
252 | | - if not self._confirm_update(): |
| 251 | + # Confirm update (skip if already confirmed) |
| 252 | + if not skip_confirmation and not self._confirm_update(): |
253 | 253 | self.console.print("[yellow]Update cancelled[/yellow]") |
254 | 254 | return False |
255 | 255 |
|
@@ -382,15 +382,23 @@ def _update_via_homebrew(self, target: Version) -> bool: |
382 | 382 |
|
383 | 383 |
|
384 | 384 | def check_for_updates_on_startup() -> None: |
385 | | - """Check for updates on CLI startup (non-blocking).""" |
| 385 | + """Check for updates on CLI startup with blocking prompt.""" |
386 | 386 | try: |
387 | 387 | # Only check if we haven't checked recently |
388 | 388 | manager = UpdateManager() |
389 | | - result = manager.check_for_updates(force=False) |
| 389 | + result = manager.check_for_updates(force=True) |
390 | 390 |
|
391 | 391 | if result.update_available: |
392 | | - console.print(f"\n[cyan]ℹ️ A new version of Codegen CLI is available: {result.latest_version}[/cyan]") |
393 | | - console.print("[dim]Run 'codegen update' to upgrade[/dim]\n") |
| 392 | + console.print(f"\n[cyan]ℹ️ A new version of Codegen CLI is available: {result.current_version} → {result.latest_version}[/cyan]") |
| 393 | + |
| 394 | + if manager.perform_update(): |
| 395 | + console.print("\n[green]✓ Update completed successfully![/green]") |
| 396 | + console.print("[yellow]Please restart your terminal or run a new codegen command to use the updated version.[/yellow]\n") |
| 397 | + # Exit after successful update |
| 398 | + sys.exit(0) |
| 399 | + else: |
| 400 | + console.print("\n[red]Update failed. Please try running 'codegen update' manually.[/red]\n") |
| 401 | + |
394 | 402 | except Exception: |
395 | 403 | # Silently ignore update check failures on startup |
396 | 404 | pass |
0 commit comments