Paginate update list output
This commit is contained in:
@@ -14,16 +14,16 @@ def detect_pkg_manager() -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
async def list_updates() -> str:
|
||||
async def list_updates() -> tuple[str, list[str]]:
|
||||
pm = detect_pkg_manager()
|
||||
if not pm:
|
||||
return "⚠️ No supported package manager found"
|
||||
return "⚠️ Updates", ["No supported package manager found"]
|
||||
|
||||
if pm == "apt":
|
||||
await run_cmd(["sudo", "apt", "update"], timeout=300)
|
||||
rc, out = await run_cmd(["apt", "list", "--upgradable"], timeout=120)
|
||||
if rc != 0:
|
||||
return f"❌ apt list failed\n```{out}```"
|
||||
return "❌ Updates (apt)", [f"apt list failed: {out}"]
|
||||
|
||||
lines = []
|
||||
for line in out.splitlines():
|
||||
@@ -47,26 +47,32 @@ async def list_updates() -> str:
|
||||
else:
|
||||
lines.append(f"{name}: -> {new_ver}")
|
||||
|
||||
body = "\n".join(lines) if lines else "No updates"
|
||||
return f"📦 Updates (apt)\n```{body}```"
|
||||
if not lines:
|
||||
lines = ["No updates"]
|
||||
return "📦 Updates (apt)", lines
|
||||
|
||||
if pm == "dnf":
|
||||
rc, out = await run_cmd(["sudo", "dnf", "check-update"], timeout=300)
|
||||
if rc in (0, 100):
|
||||
return f"📦 Updates (dnf)\n```{out}```"
|
||||
return f"❌ dnf check-update failed\n```{out}```"
|
||||
lines = out.splitlines() or ["No updates"]
|
||||
return "📦 Updates (dnf)", lines
|
||||
return "❌ Updates (dnf)", [f"dnf check-update failed: {out}"]
|
||||
|
||||
if pm == "yum":
|
||||
rc, out = await run_cmd(["sudo", "yum", "check-update"], timeout=300)
|
||||
if rc in (0, 100):
|
||||
return f"📦 Updates (yum)\n```{out}```"
|
||||
return f"❌ yum check-update failed\n```{out}```"
|
||||
lines = out.splitlines() or ["No updates"]
|
||||
return "📦 Updates (yum)", lines
|
||||
return "❌ Updates (yum)", [f"yum check-update failed: {out}"]
|
||||
|
||||
if pm == "pacman":
|
||||
rc, out = await run_cmd(["pacman", "-Qu"], timeout=120)
|
||||
return f"📦 Updates (pacman)\n```{out}```" if rc == 0 else f"❌ pacman -Qu failed\n```{out}```"
|
||||
if rc == 0:
|
||||
lines = out.splitlines() or ["No updates"]
|
||||
return "📦 Updates (pacman)", lines
|
||||
return "❌ Updates (pacman)", [f"pacman -Qu failed: {out}"]
|
||||
|
||||
return "⚠️ Unsupported package manager"
|
||||
return "⚠️ Updates", ["Unsupported package manager"]
|
||||
|
||||
|
||||
async def apply_updates() -> str:
|
||||
|
||||
Reference in New Issue
Block a user