Compact schedls show output

This commit is contained in:
mdaleo404 committed 2026-10-02 14:55:37 +01:00
1 parent 0b9b0c2164
commit beb16e5be3
2 files changed
+33 -34

No files matched your search

+28 -33
View File
@@ -101,56 +101,51 @@ def render_show(output: Output, job: ScheduledJob) -> None:
return return
output.heading(job.name) output.heading(job.name)
output.line() output.line()
output.key_values([("Status", job_status(job))]) core = [
output.line() ("Status", job_status(job)),
output.key_values([("Backend", _backend_label(job))]) ("Backend", _backend_label(job)),
output.line() ("Managed by schedls", "yes" if job.managed else "no"),
output.key_values([("Managed by schedls", "yes" if job.managed else "no")]) ("Schedule", job.schedule_text()),
output.line() ]
output.key_values([("Schedule", job.schedule_text())])
if job.schedule.expressions: if job.schedule.expressions:
for expression in job.schedule.expressions: for expression in job.schedule.expressions:
output.key_values([("OnCalendar", expression)]) core.append(("OnCalendar", expression))
output.line()
next_run = _next_run(job) next_run = _next_run(job)
output.key_values([("Next", output.job_datetime(next_run) or _next_unavailable(job))]) core.append(("Next", output.job_datetime(next_run) or _next_unavailable(job)))
output.line()
previous = output.job_datetime(job.last_run) or _previous_unavailable(job) previous = output.job_datetime(job.last_run) or _previous_unavailable(job)
core.extend([("Previous", previous), ("Command", job.command.display() or "unknown")])
if job.last_result: if job.last_result:
previous = f"{previous}\nresult: {job.last_result}" core.append(("Result", job.last_result))
output.key_values([("Previous", previous)]) output.key_values(core)
output.line()
output.key_values([("Command", job.command.display() or "unknown")]) details: list[tuple[str, str]] = []
if job.systemd is not None: if job.systemd is not None:
if job.systemd.timer_path: if job.systemd.timer_path:
output.line() details.append(("Timer", job.systemd.timer_path))
output.key_values([("Timer", job.systemd.timer_path)])
if job.systemd.service_path: if job.systemd.service_path:
output.key_values([("Service", job.systemd.service_path)]) details.append(("Service", job.systemd.service_path))
extras = [] details.append(("Persistent", "yes" if job.systemd.persistent else "no"))
extras.append(("Persistent", "yes" if job.systemd.persistent else "no"))
if job.systemd.jitter: if job.systemd.jitter:
extras.append(("Randomized delay", job.systemd.jitter)) details.append(("Randomized delay", job.systemd.jitter))
if job.systemd.accuracy: if job.systemd.accuracy:
extras.append(("Accuracy", job.systemd.accuracy)) details.append(("Accuracy", job.systemd.accuracy))
if job.systemd.working_directory: if job.systemd.working_directory:
extras.append(("Working directory", job.systemd.working_directory)) details.append(("Working directory", job.systemd.working_directory))
for key, value in job.systemd.environment: for key, value in job.systemd.environment:
extras.append(("Environment", f"{key}={value}")) details.append(("Environment", f"{key}={value}"))
if extras:
output.line()
output.key_values(extras)
if job.cron is not None: if job.cron is not None:
output.line() details.append(("Source", job.source.detail))
output.key_values([("Source", job.source.detail)])
if job.source.path: if job.source.path:
output.key_values([("File", job.source.path)]) details.append(("File", job.source.path))
if job.cron.user: if job.cron.user:
output.key_values([("Run as", job.cron.user)]) details.append(("Run as", job.cron.user))
if job.cron.shell: if job.cron.shell:
output.key_values([("SHELL", job.cron.shell)]) details.append(("SHELL", job.cron.shell))
if job.cron.mailto: if job.cron.mailto:
output.key_values([("MAILTO", job.cron.mailto)]) details.append(("MAILTO", job.cron.mailto))
if details:
output.line()
output.key_values(details)
for warning in job.warnings: for warning in job.warnings:
output.line() output.line()
output.diagnostic(f"Warning: {warning}") output.diagnostic(f"Warning: {warning}")
+5 -1
View File
@@ -89,7 +89,11 @@ def test_render_show_explains_unavailable_cron_history() -> None:
inspect_ops.render_show(output, job) inspect_ops.render_show(output, job)
assert "Previous unavailable (cron does not provide per-job history)" in stream.getvalue() text = stream.getvalue()
previous = next(line for line in text.splitlines() if line.startswith("Previous"))
assert "unavailable (cron does not provide per-job history)" in previous
assert "\n\nBackend" not in text
assert "\n\nSource" in text
def test_render_show_keeps_cron_next_run_null_in_json() -> None: def test_render_show_keeps_cron_next_run_null_in_json() -> None: