add _format_cert_table() helper for CLI cert listings

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Vlad Doloman
2026-07-08 16:20:41 +03:00
parent 17abe31650
commit 444e35f8cd
2 changed files with 73 additions and 0 deletions

View File

@@ -1262,6 +1262,22 @@ class CursesApp:
# ============================================================
def _format_cert_table(certs: list[CertInfo]) -> str:
"""Render CN / expiry / email as an aligned table, like `ls -l`."""
if not certs:
return "(no certificates)"
rows = [
(c.cn, _expiry_label(c).strip(), get_email(EASYRSA_PKI_DIR, c.cn) or "(none)")
for c in certs
]
cn_w = max(len("CN"), max(len(r[0]) for r in rows))
exp_w = max(len("EXPIRES"), max(len(r[1]) for r in rows))
lines = [f"{'CN':<{cn_w}} {'EXPIRES':<{exp_w}} EMAIL"]
for cn, exp, email in rows:
lines.append(f"{cn:<{cn_w}} {exp:<{exp_w}} {email}")
return "\n".join(lines)
class CliRunner:
"""Non-interactive runner for scripting / cron use."""