Repository navigation
feat: add requireConfirmation, previewUnlessConfirmed and printDryRun - #198
Merged
Merged
Conversation
The CLIs each hand-roll the --yes / --dry-run flow for destructive
commands, and they have drifted: todoist-cli throws
CONFIRMATION_REQUIRED and emits a { status: "preview" } object under
--dry-run --json, twist-cli and comms-cli throw MISSING_YES_FLAG and
print a plain-text dry run even under --json, and three copies of
printDryRun live in the CLIs.
requireConfirmation refuses a --json or --quiet run that has neither
--yes nor --dry-run with CONFIRMATION_REQUIRED, before any request.
previewUnlessConfirmed prints the dry-run preview (or the JSON preview
envelope), or the summary and "Use --yes to confirm." without --yes,
and reports whether it did. printDryRun is the multi-line twist-cli and
comms-cli version. CONFIRMATION_REQUIRED joins CliErrorCode.
doistbot
reviewed
Dec 3, 2026
doistbot
left a comment
Member
There was a problem hiding this comment.
This PR adds shared requireConfirmation, previewUnlessConfirmed and printDryRun helpers to the root entry point, unifying the --yes/--dry-run flow with a new CONFIRMATION_REQUIRED error code, plus tests and docs.
Few things worth tightening:
- Under
--quiet --dry-runwithout--json, the guard treats the run as script mode but the preview branch still prints human-readable rows to stdout — the exact failure the doc says it prevents. Either emit the JSON envelope forquiettoo or document the requiredquiet+jsonpairing, and pin it with a test. --ndjsonis a first-class machine mode elsewhere in the package, but the helper ignores it:--ndjsonwithout--yesprints human lines, and--ndjson --dry-runprints the plain-text dry-run block. AddndjsontoConfirmationOptionsand include it in both the guard and the preview branch.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (2)
src/confirmation.test.ts:41: The allowed-through matrix covers
--json --dry-runbut not--quiet --dry-run. Both pass only because the guard checks!options.dryRun, so a regression that made the quiet branch refuse dry runs would still be caught on the JSON half. Add['--quiet --dry-run', { quiet: true, dryRun: true }]beside the--quiet --yesrow to pin the symmetry the two script-mode flags are meant to have.README.md:23: This row only has two cells (module + exports); the
Purposecell is missing, so the row renders short and readers get no description of whatconfirmationdoes. AGENTS.md ("README maintenance") requires the "What's in it" table to reflect the change. Add the third cell, e.g. whatrequireConfirmation/previewUnlessConfirmed/printDryRundo (--yes/--dry-rungating for destructive commands, one shared implementation for the CLIs).
--quiet hides success messages rather than switching to JSON, so a --quiet --dry-run run prints the dry-run rows it asked for. Reword the docs, which called --quiet a script mode, and pin that behaviour in both helpers.
doist-release-bot Bot
added a commit
that referenced
this pull request
Dec 3, 2026
## [2.1.0](v2.0.3...v2.1.0) (2026-12-03) ### Features * add requireConfirmation, previewUnlessConfirmed and printDryRun ([#198](#198)) ([368d0c2](368d0c2))
Contributor
|
🎉 This PR is included in version 2.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This was referenced Dec 3, 2026
Merged
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.
The CLIs each hand-roll the
--yes/--dry-runflow for destructive commands, and they have drifted apart. todoist-cli throwsCONFIRMATION_REQUIRED("Pass --yes to execute …, or --dry-run to preview it.") and emits a{ status: "preview", command, messages }object under--dry-run --json. twist-cli and comms-cli throwMISSING_YES_FLAGand print a plain-text dry run even under--json. todoist-cli, twist-cli and comms-cli each carry their ownprintDryRun.This adds the shared version to the root entry point:
requireConfirmation(options, { command, hints })throwsCONFIRMATION_REQUIREDwhen a--jsonor--quietrun has neither--yesnor--dry-run. Callers run it before any request, so a refused run sends nothing.quietcomes from each CLI's own global args store.previewUnlessConfirmed(options, { command, action, summary, notes, details })runs the same guard, then prints the JSON preview envelope (--dry-run --json), theprintDryRunrows (--dry-run), or the summary, notes andUse --yes to confirm.(no--yes), and returnstruewhen it printed a preview.notesdouble as the error's hints and the envelope's extra messages.printDryRun(action, details)is the twist-cli and comms-cli version, which indents the continuation lines of a multi-line value. For single-line values it prints exactly what todoist-cli's copy prints.CONFIRMATION_REQUIREDjoinsCliErrorCode. The change is additive. todoist-cli adopts it in a follow-up once this is released, with no behaviour change there. twist-cli and comms-cli would switch fromMISSING_YES_FLAGtoCONFIRMATION_REQUIREDwhen they adopt it, which is a breaking change for their scripts, so those are separate decisions.