Return an update notification message if a newer version exists.
(current: str)
| 57 | |
| 58 | |
| 59 | def get_update_message(current: str) -> str | None: |
| 60 | """Return an update notification message if a newer version exists.""" |
| 61 | latest = get_latest_version_cached() |
| 62 | if not latest or not current: |
| 63 | return None |
| 64 | try: |
| 65 | from packaging.version import Version |
| 66 | |
| 67 | if Version(latest) > Version(current): |
| 68 | return f"Update available: {current} -> {latest}\nRun 'uv tool install --force unity-cli' to update" |
| 69 | except ImportError: |
| 70 | # packaging not available; fall back to tuple comparison |
| 71 | def _parse_version(v: str) -> tuple[int, ...]: |
| 72 | return tuple(int(x) for x in v.split(".")) |
| 73 | |
| 74 | try: |
| 75 | if _parse_version(latest) > _parse_version(current): |
| 76 | return f"Update available: {current} -> {latest}\nRun 'uv tool install --force unity-cli' to update" |
| 77 | except (ValueError, TypeError): |
| 78 | pass |
| 79 | return None |