Skip to content

Commit af881e4

Browse files
authored
fix: update prompt for auto update (#1262)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent e9f8e63 commit af881e4

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/codegen/cli/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ def version_callback(value: bool):
6161

6262
# Check for updates on startup (non-blocking)
6363
try:
64-
from codegen.cli.commands.update import check_for_updates_on_startup
65-
66-
# Only check on actual command runs, not completions
64+
# Only check when no arguments are passed (just "codegen" to launch TUI)
6765
import sys
6866

69-
if not any(arg in sys.argv for arg in ["--help", "-h", "completion", "--version"]):
67+
from codegen.cli.commands.update import check_for_updates_on_startup
68+
69+
if len(sys.argv) == 1:
7070
check_for_updates_on_startup()
7171
except ImportError:
7272
pass # Update check dependencies not available

src/codegen/cli/commands/update/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from rich.console import Console
1010

1111
import codegen
12-
from .updater import UpdateManager, check_for_updates_on_startup
12+
13+
from .updater import UpdateManager
1314

1415
console = Console()
1516

src/codegen/cli/commands/update/updater.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Update configuration
2525
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
2727

2828

2929
class InstallMethod(Enum):
@@ -219,7 +219,7 @@ def _save_last_check_time(self) -> None:
219219
with open(UPDATE_CHECK_FILE, "w") as f:
220220
json.dump({"last_check": datetime.now().isoformat()}, f)
221221

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:
223223
"""Perform the update to a specific version or latest."""
224224
current_version = self._get_current_version()
225225

@@ -248,8 +248,8 @@ def perform_update(self, target_version: Optional[str] = None, dry_run: bool = F
248248
if dry_run:
249249
return True
250250

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():
253253
self.console.print("[yellow]Update cancelled[/yellow]")
254254
return False
255255

@@ -382,15 +382,23 @@ def _update_via_homebrew(self, target: Version) -> bool:
382382

383383

384384
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."""
386386
try:
387387
# Only check if we haven't checked recently
388388
manager = UpdateManager()
389-
result = manager.check_for_updates(force=False)
389+
result = manager.check_for_updates(force=True)
390390

391391
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+
394402
except Exception:
395403
# Silently ignore update check failures on startup
396404
pass

0 commit comments

Comments
 (0)