Skip to content

refactor(cli): split bin/confluence.js into domain command modules#186

Merged
pchuri merged 6 commits into
mainfrom
refactor/extract-command-groups
May 12, 2026
Merged

refactor(cli): split bin/confluence.js into domain command modules#186
pchuri merged 6 commits into
mainfrom
refactor/extract-command-groups

Conversation

@pchuri
Copy link
Copy Markdown
Owner

@pchuri pchuri commented May 12, 2026

Summary

  • Extract 17 commands across 6 domain groups out of bin/confluence.js into dedicated modules under bin/commands/: profile, versions, attachments, properties, comment, export.
  • Shrink bin/confluence.js from 2077 → 869 lines (−58%); each new module is self-contained with its own requires and registers via a small register*(program, { withClient | withLocal }) function called from the entrypoint.
  • Migrate the four profile * actions onto the withLocal helper so they share the standard analytics + error pipeline instead of inline try/catch + process.exit(1) (knocks out part of the unmigrated-commands review finding).
  • Move the export helpers (EXPORT_MARKER, writeExportMarker, isExportDirectory, sanitizeFilename, uniquePathFor, writeStream, sanitizeTitle, exportRecursive) into bin/commands/export.js; tests/export.test.js now imports them directly from the new module instead of via the _test block.

Each commit is one group, in extraction order: profile → versions → attachments → properties → comment → export. Diffs per commit are small and independently reviewable.

What did NOT change

  • No behavior changes: every command name, option flag, default, prompt, exit code, and analytics key is preserved verbatim.
  • The comment_create onError hint and the *_cancel analytics keys are intact.
  • The withClient / withLocal helpers themselves are unchanged.
  • attachments and export both need sanitizeFilename; rather than introducing a shared util layer, each module keeps its own copy. Easy to refactor later if more duplication appears.

Test plan

  • npx jest — 16 suites / 682 tests pass after every commit
  • npx eslint bin/ tests/ — clean
  • node bin/index.js --help lists all 33 commands
  • --help for one command in each extracted group preserves option list verbatim
  • confluence profile add "bad name" triggers the new withLocal error pipeline (Error: Invalid profile name..., exit 1)

pchuri added 6 commits May 13, 2026 00:03
Move `profile list/use/add/remove` into a dedicated module and migrate
the four actions onto the `withLocal` helper so they share the standard
analytics + error pipeline instead of inline try/catch + process.exit(1).
Move `versions`, `version-delete`, and `versions-purge` into a dedicated
module. No behavior changes — same prompts, exit codes, and analytics keys.
…s.js

Move `attachments`, `attachment-upload`, and `attachment-delete` into a
dedicated module. The download path's inline `sanitizeFilename` is
duplicated here rather than imported, keeping the module self-contained
(the export command keeps its own copy when it moves out next).
Move `property-list`, `property-get`, `property-set`, and
`property-delete` into a dedicated module.
Move `comments`, `comment`, and `comment-delete` into a dedicated module
along with their three rendering helpers (`parseLocationOptions`,
`formatBodyBlock`, `buildCommentTree`), which are only used here. The
`comment_create` onError hint and the `comment_delete_cancel` analytics
key are preserved.
…ort.js

Move the `export` command along with EXPORT_MARKER and its six helpers
(writeExportMarker, isExportDirectory, sanitizeFilename, uniquePathFor,
writeStream, sanitizeTitle, exportRecursive) into a dedicated module.
The helpers are re-exposed from the new module for unit testing; the
`_test` block in bin/confluence.js drops them since they no longer live
there, and tests/export.test.js imports directly from the new module.
@pchuri pchuri self-assigned this May 12, 2026
@pchuri pchuri merged commit 3df13e6 into main May 12, 2026
6 checks passed
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