Skip to content

refactor(cli): de-dup setup/subject config commands - #78

Merged
larsrollik merged 1 commit into
mainfrom
refactor/cli-config-command-dedup
Aug 17, 2026
Merged

refactor(cli): de-dup setup/subject config commands#78
larsrollik merged 1 commit into
mainfrom
refactor/cli-config-command-dedup

Conversation

@larsrollik

Copy link
Copy Markdown
Member

Behaviour-preserving cleanup of the msw setup / msw subject config-command handlers in cli/execute.py.

What

  • _write_yaml(path, data) — collapses the four identical yaml.dump(..., default_flow_style=False, allow_unicode=True, sort_keys=False) blocks in run_setup/run_subject into one helper.
  • _rename_config(dir, old, new, *, force, label) — collapses the near-identical setup/subject rename flows into one helper, parameterised by a capitalised label so every user-facing message (Renamed setup …, … not found at …, … already exists … Use --force) stays byte-for-byte identical. The setup-only empty-name guard remains inline in run_setup.
  • Drop the __import__("sys") / __import__("datetime") hacks in run_subjectsys was already imported at module top; added a proper import datetime.

Tests

Adds tests/test_cli_config_commands.py — the setup/subject create + rename commands had no coverage. The tests pin the on-disk YAML shape (name, seeded bpod device, registered timestamp) and the rename-updates-name / refuse-existing-without-force behaviour that the shared helpers now depend on.

No behaviour change; full msw-core suite green.

- Extract `_write_yaml()` for the repeated yaml.dump options and
  `_rename_config()` for the near-identical setup/subject rename flows in
  run_setup/run_subject; all user-facing messages are preserved verbatim.
- Replace the `__import__("sys")`/`__import__("datetime")` calls in
  run_subject with the existing module `sys` import and a proper
  `import datetime`.
- Add characterization tests for the setup/subject create + rename
  commands, which previously had no coverage.

Patch bump (refactor).
@larsrollik
larsrollik requested a review from a team as a code owner August 15, 2026 22:49
@larsrollik
larsrollik merged commit c496a22 into main Aug 17, 2026
7 checks passed
@larsrollik
larsrollik deleted the refactor/cli-config-command-dedup branch August 17, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant