Document all accepted fields for the catch-all write commands - #636
Document all accepted fields for the catch-all write commands#636swissspidy wants to merge 3 commits into
Conversation
`user update`, `post create`, `post update`, `comment create` and `comment update` accept `--<field>=<value>`, and their documented field lists have drifted from what core actually accepts. `comment update` documented no fields at all. Fill the lists in from the wp_insert_user(), wp_insert_post() and wp_update_comment() docblocks in core: - user update: syntax_highlighting, comment_shortcuts, admin_color, use_ssl, user_activation_key, spam, show_admin_bar_front, locale, meta_input - post create: page_template, import_id - post update: page_template - comment create / comment update: the full column set, including the mixed-case comment_author_IP and comment_post_ID Two related changes: - `user application-password update` advertised `--<field>=<value>` while documenting that only `name` is supported. Core's WP_Application_Passwords::update_application_password() only ever reads `$update['name']`, so declare that parameter and drop the catch-all. The command is then validated without depending on anything else. - `--meta_input` and `--comment_meta` take arrays, so run them through Utils\parse_shell_arrays() the way Post_Command::update() already does. Without it a JSON value reaches core as a string. The new parameters have no effect on validation on their own, since the catch-all still suppresses it. They are what gives typo detection something accurate to match against. Refs wp-cli/wp-cli#5286 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe CLI documentation now lists additional comment, post, user, and application-password options. Comment and user update commands parse shell-array metadata before applying WordPress slashing and persistence. ChangesCLI command updates
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This PR documents accepted command fields and corrects array parsing and application-password argument handling without introducing an identified merge-blocking risk; it is merge-ready after normal checks and review. Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
PHPStan reported two errors on the calls added in the previous commit: Parameter #1 $assoc_args of function WP_CLI\Utils\parse_shell_arrays expects array<string, string>, array<string, mixed> given. Utils\parse_shell_arrays() is annotated for string values throughout, while Comment_Command's methods correctly declare their arguments as array<string, mixed> - a flag arrives as true, not as a string. Rather than weaken that annotation, hand the function only the one key it needs to look at, and only when it holds a string. That is not a workaround for the type checker: is_json() rejects anything that is not a string, so a non-string value was never going to be parsed either way. Post_Command makes the same call without complaint only because its $assoc_args parameters carry no type at all, and missingType.parameter is in the ignore list. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
wp-cli/wp-cli#6393 corrected parse_shell_arrays()'s $assoc_args parameter to array<string, mixed>, which is what it always accepted. The local wrapper existed only to work around the previous annotation, so revert to the plain call and let all four call sites in this repo look the same again. This does not need to wait for a wp-cli release: composer.json sets minimum-stability to dev and requires ^3.0, which resolves to dev-main. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
Opened to make the documentation side of wp-cli/wp-cli#5286 concrete. Pairs with wp-cli/wp-cli#6392, which adds the typo detection itself — but this PR stands on its own and is useful without it.
Why this first
Every approach discussed on #5286 needs the same foundation: an accurate list of what each command actually accepts. Typo detection matches an unknown argument against the documented ones, so an incomplete docblock means either missed typos or false positives.
comment updatedocumented no fields at all.On its own this PR does not change validation. The catch-all still suppresses unknown-parameter checking, so the added parameters only improve
wp helpoutput today. They are what gives the matcher something accurate to work with.Where the lists come from
The
wp_insert_user(),wp_insert_post()andwp_update_comment()docblocks in core trunk, rather than the 2019 list on the issue — that one predatesuser_activation_key/spam(5.3) andmeta_input(5.9).user updatesyntax_highlighting,comment_shortcuts,admin_color,use_ssl,user_activation_key,spam,show_admin_bar_front,locale,meta_inputpost createpage_template,import_idpost updatepage_templatecomment createcomment updateTwo changes that are not documentation
Flagged separately because they are easy to drop if you'd rather keep this PR pure.
user application-password updateadvertised--<field>=<value>while its own text said onlynamewas supported. Core'sWP_Application_Passwords::update_application_password()only ever reads$update['name'], so extra keys were silently ignored. Replaced the catch-all with[--name=<name>]. That command is now validated immediately, without depending on the framework PR.--meta_inputand--comment_metatake arrays, so they go throughUtils\parse_shell_arrays()the wayPost_Command::update()already does. Without it a JSON value reaches core as a string. Documenting them without this would have meant documenting parameters that don't work.The second one originally tripped PHPStan, because
parse_shell_arrays()was annotatedarray<string, string>whileComment_Commandcorrectly declaresarray<string, mixed>. That turned out to be an upstream annotation bug and is fixed in wp-cli/wp-cli#6393, so all four call sites in this repo are now the same plain one-liner. No release is needed for that —composer.jsonsetsminimum-stability: devand requires^3.0, which resolves todev-main.Verification
comment_author_IPandcomment_post_IDare mixed-case, so they depend on #6388. Against the parser before that fix they register truncated:Against current
mainall seven commands parse cleanly, with no truncated names and no unknown tokens:Two things I noticed but did not change
Both are pre-existing and orthogonal, and both now have tests and fixes in #637.
post update --post_modified/--post_modified_gmtare documented but ignored.wp_insert_post()computes both itself and never reads them from$postarr.user createdocuments--user_nicenameand--rich_editingbut never applies them.User_Command::create()builds an explicitstdClassand neither property is set. That command has no catch-all, so it is strictly validated and still silently drops the value — the same failure as #5286, from the other direction.🤖 Generated with Claude Code
https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
Summary by CodeRabbit
Documentation
Bug Fixes