Skip to content

CLI: Make yargs args strict#48047

Merged
tbradsha merged 4 commits intotrunkfrom
fix/tools/prevent_invalid_flags_in_cli
Apr 14, 2026
Merged

CLI: Make yargs args strict#48047
tbradsha merged 4 commits intotrunkfrom
fix/tools/prevent_invalid_flags_in_cli

Conversation

@tbradsha
Copy link
Copy Markdown
Contributor

@tbradsha tbradsha commented Apr 10, 2026

Proposed changes

This one's a bit silly, but I was trying to use --with-deps instead of --deps when building, and it would happily build with no errors, but of course didn't build deps. By switching yargs to strict by default, it now shows the help page when there's an invalid arg passed.

Another common error is trying to use --filter with the test command, which isn't supported.

Some commands need option passthrough. Both composer and pnpm already override with .strict( false ). I added changelog and docker as well.

There's also docker, which can use --, but those are handled differently in argv._. It turns out docker also needs passthrough, as it does things like jetpack docker wp plugin --activate.

Note that strict mode doesn't like negative (no-*) options by default. I could have set boolean-negation and update the JS vars, but I decided to just define the positive options as hidden.

Related product discussion/links

Does this pull request change what data or activity we track or use?

Testing instructions

Test various jetpack commands with valid and invalid flags, e.g.:

  • jetpack build plugins/crm --deps: builds with deps
  • jetpack build plugins/crm --with-deps: shows help
  • jetpack pnpm --version: shows pnpm version
  • jetpack composer --version: shows composer version
  • jetpack test js packages/connection --filter=asdf: shows help
  • jetpack docker phpunit jetpack -- --filter=Jetpack_Components_Test: runs filtered set of tests

@tbradsha tbradsha self-assigned this Apr 10, 2026
@tbradsha tbradsha requested a review from a team as a code owner April 10, 2026 20:11
@tbradsha tbradsha added the [Status] Needs Review This PR is ready for review. label Apr 10, 2026
@github-actions github-actions Bot added the [Tools] Development CLI The tools/cli to assist during JP development. label Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Apparently `yargs` has boolean negation enabled by default (so an option called `do-thing` automatically has a opposite option `no-do-thing`).

* No strict mode: Either the negative or positive variant (or both) can be specified as an option, and the value is stored as the positive-named property (`argv.doThing`).
* Strict mode: The positive variant must be specified as an option, or else it'll complain that that the positive-named variant is an unknown arg.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the fix/tools/prevent_invalid_flags_in_cli branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/tools/prevent_invalid_flags_in_cli
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/tools/prevent_invalid_flags_in_cli

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented Apr 10, 2026

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

Copy link
Copy Markdown
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

I wonder if jetpack changelog needs non-strict as well. Or else going through and declaring any missing options, such as --filename-auto-suffix for jetpack changelog add.

Other than that, LGTM.

@tbradsha
Copy link
Copy Markdown
Contributor Author

I wonder if jetpack changelog needs non-strict as well

Good catch. validate has --files, write has --now, and squash has a bunch...let's make it not strict:

80c2d6e

@tbradsha tbradsha merged commit feafced into trunk Apr 14, 2026
144 of 147 checks passed
@tbradsha tbradsha deleted the fix/tools/prevent_invalid_flags_in_cli branch April 14, 2026 18:09
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Tools] Development CLI The tools/cli to assist during JP development.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants