refactor(cli): extract plan formatters from cmd_plan (S3776) #66

Open
Claude wants to merge 1 commit from Claude/backup-script:fix/issue-21-S3776-cmd-plan-complexity into master
First-time contributor

Closes #21

cmd_plan mixed config loading, planning, JSON serialization and
pretty-printing in one function — cognitive complexity 16, over SonarQube's
15-line ceiling.

Refactor

Extraction Job
_plan_to_json_dict(plan) Build the JSON payload (preflight steps + jobs)
_print_plan_text(plan) Pretty-print the human-readable form

After the split, cmd_plan is ~10 lines (complexity ~3), and each helper
sits well under the ceiling. Behavior is byte-for-byte identical to master.

Note

plan: Any annotation on the helpers avoids a top-level import of
gardien.core.planner.Plan — the existing cmd_plan body uses a deferred
import (inside the function) for the same reason. Keeping the helpers
loosely typed preserves the current import shape; if the strict-typing
boundary expands to cover cli.py, the annotation can be tightened then.

Verification

  • pytest -q tests/unit/ — 211 passed
  • ruff check src/gardien/cli.py — no new errors (4 pre-existing PTH errors unchanged)
Closes #21 `cmd_plan` mixed config loading, planning, JSON serialization and pretty-printing in one function — cognitive complexity 16, over SonarQube's 15-line ceiling. ### Refactor | Extraction | Job | |---|---| | `_plan_to_json_dict(plan)` | Build the JSON payload (preflight steps + jobs) | | `_print_plan_text(plan)` | Pretty-print the human-readable form | After the split, `cmd_plan` is ~10 lines (complexity ~3), and each helper sits well under the ceiling. Behavior is byte-for-byte identical to master. ### Note `plan: Any` annotation on the helpers avoids a top-level import of `gardien.core.planner.Plan` — the existing `cmd_plan` body uses a deferred import (inside the function) for the same reason. Keeping the helpers loosely typed preserves the current import shape; if the strict-typing boundary expands to cover `cli.py`, the annotation can be tightened then. ### Verification - `pytest -q tests/unit/` — 211 passed - `ruff check src/gardien/cli.py` — no new errors (4 pre-existing PTH errors unchanged)
cmd_plan mixed config loading, planning, JSON serialization and pretty
printing in one function — cognitive complexity 16 (SonarQube ceiling: 15).

Split out:
  _plan_to_json_dict(plan)  — build the JSON payload
  _print_plan_text(plan)    — pretty-print the human-readable form

cmd_plan drops to ~10 lines and a complexity of ~3; the two helpers each
have complexity ≤4. Behavior is identical.

Refs bc1bb/backup-script#21
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix/issue-21-S3776-cmd-plan-complexity:Claude-fix/issue-21-S3776-cmd-plan-complexity
git switch Claude-fix/issue-21-S3776-cmd-plan-complexity

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff Claude-fix/issue-21-S3776-cmd-plan-complexity
git switch Claude-fix/issue-21-S3776-cmd-plan-complexity
git rebase master
git switch master
git merge --ff-only Claude-fix/issue-21-S3776-cmd-plan-complexity
git switch Claude-fix/issue-21-S3776-cmd-plan-complexity
git rebase master
git switch master
git merge --no-ff Claude-fix/issue-21-S3776-cmd-plan-complexity
git switch master
git merge --squash Claude-fix/issue-21-S3776-cmd-plan-complexity
git switch master
git merge --ff-only Claude-fix/issue-21-S3776-cmd-plan-complexity
git switch master
git merge Claude-fix/issue-21-S3776-cmd-plan-complexity
git push origin master
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
bc1bb/backup-script!66
No description provided.