refactor: delegate ol changelog to @doist/cli-core/commands#69
Merged
Conversation
…te cli-core errors through formatter
- `src/commands/changelog.ts` is now a thin wrapper over `registerChangelogCommand` from `@doist/cli-core/commands`, configured with outline's repo URL, package version, and `bulletMarkers: ['*', '-']`. Local parsing/formatting (~110 lines) deleted — cli-core covers the behavior.
- `src/lib/errors.ts` re-exports `CoreCliError` as `BaseCliError` so the top-level handler matches both outline-thrown and cli-core-thrown errors.
- `src/lib/output.ts` widens `formatError` to accept a `BaseCliError` instance and adds `formatErrorJson` for `{error: {code, message, hints}}` envelopes.
- `src/lib/global-args.ts` adds `isJsonMode()` backed by cli-core's `parseGlobalArgs` argv scan.
- `src/index.ts` declares `--json` / `--ndjson` at the program level (with `enablePositionalOptions()`) and routes `BaseCliError` through `formatError` / `formatErrorJson` based on `isJsonMode()`.
- Local changelog tests slimmed to two wrapper smoke tests; output tests cover the new instance/JSON paths.
Mirrors todoist-cli#319.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
doistbot
reviewed
May 11, 2026
Member
doistbot
left a comment
There was a problem hiding this comment.
This PR cleanly delegates the changelog command to @doist/cli-core and introduces helpful top-level error handling for JSON output. These updates significantly streamline the codebase by reusing core utilities and establishing a more consistent error-reporting contract. A few adjustments are noted regarding the impact of positional options on existing global flags, ensuring consistent JSON flag behavior across successful commands, and refining the test suite and agent skill documentation to fully capture the new functionality.
- Drop the program-level --json/--ndjson + enablePositionalOptions experiment. It regressed `ol <sub> --no-spinner` / `--accessible` (root-only flags became unknown options on subcommands) and the description was a lie (root --json never reached getOutputOptions). isJsonMode() still works via cli-core's argv scan; the catch in src/index.ts is unchanged.
- Simplify resolveErrorParts → toCliError: when given a string, return a real BaseCliError instead of mapping properties by hand.
- Derive changelog repoUrl from package.json's repository.url (strip git+/.git) instead of hard-coding the URL.
- Rewrite changelog.test.ts to mock @doist/cli-core/commands directly and assert the config object (path basename, repoUrl, version, bulletMarkers ['*', '-']). Drops the brittle coupling to cli-core's internal fs reads and uses basename() for Windows-portable assertions.
- Add changelog-integration.test.ts: registers the real changelog command and asserts parseAsync rejects with BaseCliError('INVALID_TYPE') for `-n abc`, then runs that error through formatError + formatErrorJson.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/commands/changelog.tsis now a thin wrapper overregisterChangelogCommandfrom@doist/cli-core/commands, passingpath,repoUrl,version, andbulletMarkers: ['*', '-'](preserves outline's local support for both bullet styles). Drops ~110 lines of local parsing/formatting now owned by cli-core.src/index.tsnow matchesinstanceof BaseCliErrorso errors thrown from cli-core helpers (e.g. the delegatedchangelogcommand'sINVALID_TYPE/FILE_READ_ERROR) route throughformatError/formatErrorJson. The localCliErrorextends the same base, so existing throws still match.--jsonand--ndjsonat the program level withenablePositionalOptions(), plus anisJsonMode()helper insrc/lib/global-args.tsbacked by cli-core'sparseGlobalArgsargv scan.ol --json <subcommand>now produces a JSON error envelope for anyBaseCliErrorthrown after parsing.formatError/formatErrorJson— widened insrc/lib/output.tsto accept either positional(code, message, hints?)or aBaseCliErrorinstance.src/lib/errors.ts— re-exportsCoreCliErrorasBaseCliErrorso the top-levelinstanceofcheck covers both.Mirrors todoist-cli#319. No
@doist/cli-coreversion bump (already on0.9.0).Behavior changes
ol changelog -n abcnow exits non-zero withError: INVALID_TYPE / Count must be a positive integer(was a customchalk.red('Error:')line withCount must be a positive number) — intentional alignment with the cli-core contract.ol --json changelog -n abcnow emits{"error":{"code":"INVALID_TYPE","message":"Count must be a positive integer"}}.--json/--ndjsonnow appear as global options inol --help(existing per-subcommand--jsonflags still work the same).Test plan
npm run type-checknpm run lint:check+npm run format:checknpm test(108 tests pass; changelog suite slimmed from 6 tests to 2 wrapper smoke tests covering path-passthrough and footer URL; output suite gainsBaseCliError-instance +formatErrorJsoncases)ol changelog -n 1— version block + footer link unchangedol changelog -n abc— human red error, exit 1ol --json changelog -n abc— JSON error envelope, exit 1ol doc list --json— per-subcommand--jsonstill routes to output formatter🤖 Generated with Claude Code