Skip to content

Error on unsupported flags for individual CLI commands#1889

Merged
Andarist merged 8 commits intochangesets:mainfrom
mixelburg:fix/warn-unknown-flags
Mar 26, 2026
Merged

Error on unsupported flags for individual CLI commands#1889
Andarist merged 8 commits intochangesets:mainfrom
mixelburg:fix/warn-unknown-flags

Conversation

@mixelburg
Copy link
Copy Markdown
Contributor

Fixes #1827

Currently the CLI silently ignores any flag it doesn't recognise and proceeds to run the command. This can lead to confusing behaviour — e.g. a typo in --otp silently results in publishing without an OTP.

This PR adds a warning printed via @changesets/logger whenever mri surfaces a parsed flag that isn't in the known set:

$ changeset publish --otpp 123456
🦋 warn Unknown flag: --otpp

Multiple unknown flags are collected and shown together:

$ changeset add --emptty --opeen
🦋 warn Unknown flags: --emptty, --opeen

The known set includes all declared boolean/string flags, their alias canonical names, the deprecated v1 flags (updateChangelog, isPublic, skipCI, commit) that already have their own error path in run.ts, and the built-in help/version flags.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: 5cdc4a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@changesets/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 52.17391% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.24%. Comparing base (42943b7) to head (5cdc4a9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/cli/src/run.ts 50.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1889      +/-   ##
==========================================
- Coverage   84.57%   84.24%   -0.33%     
==========================================
  Files          55       56       +1     
  Lines        2399     2419      +20     
  Branches      726      723       -3     
==========================================
+ Hits         2029     2038       +9     
- Misses        364      375      +11     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/cli/src/index.ts Outdated
(key) => key !== "_" && !knownFlags.has(key)
);

if (unknownFlags.length > 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, I'd love to just migrate away from mri to something that would handle such things for us, something that would also provide us with better type-safety.

@beeequeue would you maybe have any recommendations for an alternative?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've used sade before which worked well and is teeny-tiny (44kb), but it isn't type safe. it could be used with a little manual parsing

there's also cleye which i haven't used (yet?). it's bigger (166kb) and does proper type safety and parsing.

Copy link
Copy Markdown

@beeequeue beeequeue Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can also recommend possibly changing the config parsing to use valibot, it would be easier to maintain in the long run, and if we make sure to bundle it it would also be very small.

valibot is 2MB to install since it has many types and checks, but treeshakes extremely well.

@Andarist Andarist force-pushed the fix/warn-unknown-flags branch from 5c018c4 to ed7ea4f Compare March 25, 2026 17:46
@Andarist Andarist force-pushed the fix/warn-unknown-flags branch from ed7ea4f to 7225497 Compare March 25, 2026 17:49
@Andarist Andarist changed the title fix(cli): warn when unknown flags are passed Error on unsupported flags for individual CLI commands Mar 26, 2026
@Andarist Andarist enabled auto-merge March 26, 2026 22:34
@Andarist Andarist disabled auto-merge March 26, 2026 22:52
@Andarist Andarist merged commit 96ca062 into changesets:main Mar 26, 2026
4 of 6 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 25, 2026
nnecec pushed a commit to nnecec/changesets-docs that referenced this pull request Apr 16, 2026
* fix(cli): warn when unknown flags are passed

* refactor

* strip aliases

* fix mri annoying mutation

* validate init too

* remove redundant `gitTag` default that got in a way

* add changeset

---------

Co-authored-by: Maks Pikov <mixelburg@users.noreply.github.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
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.

CLI silently ignores unknown flags and proceeds to execute commands

3 participants