Skip to content

Commit 6600b8a

Browse files
committed
Add check for available upgrades
1 parent 634f5cc commit 6600b8a

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
- Links to plugins on public PyPI
1515

16+
### Added
17+
18+
- Automatic check and notification of available upgrades
19+
1620
## [0.0.4] - 2025-04-10
1721

1822
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
requires-python = ">=3.9"
77
name = "minimal-pba-cli"
8-
version = "0.0.4"
8+
version = "0.0.5"
99
description = "A minimal command-line interface using plugin-based architecture"
1010
authors = [
1111
{ name = "Dane Hillard", email = "[email protected]" }

src/minimal_pba_cli/cli.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import atexit
12
import traceback
23
import importlib
34
from typing import Annotated
45

6+
import requests
57
import typer
68
from typer.main import get_group
79
from trogon import Trogon
810
from rich.console import Console
11+
from rich.panel import Panel
912

1013
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
1215
from minimal_pba_cli.customization import list_available_commands, create_command_wrapper
1316

1417

@@ -65,3 +68,31 @@ def _register_plugins(app: typer.Typer):
6568
"[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"
6669
)
6770
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

Comments
 (0)