|
| 1 | +import atexit |
1 | 2 | import traceback |
2 | 3 | import importlib |
3 | 4 | from typing import Annotated |
4 | 5 |
|
| 6 | +import requests |
5 | 7 | import typer |
6 | 8 | from typer.main import get_group |
7 | 9 | from trogon import Trogon |
8 | 10 | from rich.console import Console |
| 11 | +from rich.panel import Panel |
9 | 12 |
|
10 | 13 | from minimal_pba_cli.upgrade import upgrade |
11 | | -from minimal_pba_cli.plugin import plugin, find_plugins |
| 14 | +from minimal_pba_cli.plugin import plugin, find_plugins, get_latest_version |
12 | 15 | from minimal_pba_cli.customization import list_available_commands, create_command_wrapper |
13 | 16 |
|
14 | 17 |
|
@@ -65,3 +68,31 @@ def _register_plugins(app: typer.Typer): |
65 | 68 | "[red]As an example, you can run [bold cyan]DISABLE_PLUGINS=true pba-cli plugin uninstall <plugin>[/bold cyan] to remove a problematic plugin or [bold cyan]DISABLE_PLUGINS=true pba-cli plugin install <plugin>[/bold cyan] to attempt to upgrade a plugin.[/red]\n" |
66 | 69 | ) |
67 | 70 | continue |
| 71 | + |
| 72 | + |
| 73 | +def _upgrade_check() -> None: |
| 74 | + try: |
| 75 | + current_version, latest_version, is_upgrade = get_latest_version("minimal-pba-cli") |
| 76 | + except requests.exceptions.RequestException: |
| 77 | + typer.secho( |
| 78 | + "Checking for minimal-pba-cli updates failed.", |
| 79 | + fg=typer.colors.YELLOW, |
| 80 | + ) |
| 81 | + return |
| 82 | + |
| 83 | + if is_upgrade: |
| 84 | + console = Console() |
| 85 | + changelog_link = "[link=https://github.com/easy-as-python/minimal-pba-cli/blob/main/CHANGELOG.md]changelog[/link]" |
| 86 | + console.print( |
| 87 | + Panel( |
| 88 | + f""":rocket: Update available! |
| 89 | +
|
| 90 | +[yellow]{current_version}[/yellow] -> [bold green]{latest_version}[/bold green] ({changelog_link}) |
| 91 | +
|
| 92 | +Run [bold]pba-cli upgrade[/bold] to upgrade.""", |
| 93 | + expand=False, |
| 94 | + padding=(1, 10), |
| 95 | + ) |
| 96 | + ) |
| 97 | + |
| 98 | +atexit.register(_upgrade_check) |
0 commit comments