Skip to content

Commit 2e08063

Browse files
committed
cli/sync(refactor[sync]) Extract _emit_summary helper to deduplicate summary emission
why: The summary emit logic (structured event + human-readable text) was duplicated across three call sites, risking format drift. what: - Extract _emit_summary(formatter, colors, summary) helper - Replace all three call sites with the helper - Exit-on-error path now also emits human-readable summary
1 parent ba3311b commit 2e08063

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

src/vcspull/cli/sync.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -704,15 +704,7 @@ def sync(
704704
"previewed": 0,
705705
"failed": unmatched_count,
706706
}
707-
formatter.emit({"reason": "summary", **summary})
708-
if formatter.mode == OutputMode.HUMAN:
709-
formatter.emit_text(
710-
f"\n{colors.info('Summary:')} "
711-
f"{summary['total']} repos, "
712-
f"{colors.success(str(summary['synced']))} synced, "
713-
f"{colors.warning(str(summary['previewed']))} previewed, "
714-
f"{colors.error(str(summary['failed']))} failed",
715-
)
707+
_emit_summary(formatter, colors, summary)
716708
else:
717709
formatter.emit_text(
718710
colors.warning("No repositories matched the criteria."),
@@ -793,12 +785,7 @@ def silent_progress(output: str, timestamp: datetime) -> None:
793785
f"{colors.error(str(e))}",
794786
)
795787
if exit_on_error:
796-
formatter.emit(
797-
{
798-
"reason": "summary",
799-
**summary,
800-
},
801-
)
788+
_emit_summary(formatter, colors, summary)
802789
formatter.finalize()
803790
if parser is not None:
804791
parser.exit(status=1, message=EXIT_ON_ERROR_MSG)
@@ -813,13 +800,18 @@ def silent_progress(output: str, timestamp: datetime) -> None:
813800
f"{colors.muted('→')} {display_repo_path}",
814801
)
815802

816-
formatter.emit(
817-
{
818-
"reason": "summary",
819-
**summary,
820-
},
821-
)
803+
_emit_summary(formatter, colors, summary)
804+
805+
formatter.finalize()
806+
822807

808+
def _emit_summary(
809+
formatter: OutputFormatter,
810+
colors: Colors,
811+
summary: dict[str, int],
812+
) -> None:
813+
"""Emit the structured summary event and optional human-readable text."""
814+
formatter.emit({"reason": "summary", **summary})
823815
if formatter.mode == OutputMode.HUMAN:
824816
formatter.emit_text(
825817
f"\n{colors.info('Summary:')} "
@@ -829,8 +821,6 @@ def silent_progress(output: str, timestamp: datetime) -> None:
829821
f"{colors.error(str(summary['failed']))} failed",
830822
)
831823

832-
formatter.finalize()
833-
834824

835825
def progress_cb(output: str, timestamp: datetime) -> None:
836826
"""CLI Progress callback for command."""

0 commit comments

Comments
 (0)