wp-cli / ideas

💡 Ideas and feature requests are collected here
40 stars 1 forks source link

Create a Rest Controller scaffold command. #57

Open BE-Webdesign opened 7 years ago

BE-Webdesign commented 7 years ago

Hi Folks!

The scaffold commands are really invaluable, and I was wondering if wp-cli could feature a scaffolding command for creating REST API controllers. For the most part controllers are just massive boilerplate (which is good), and I think it would be great to have a wp-cli command to generate that boilerplate. It could by default output routes for EDITABLE, DELETABLE, CREATABLE, and READABLE. Then in one of the flags you could override that to only get what you need. I would be willing to help create these commands, but would first like to know more about the WP CLI process.

Thank you, wp-cli rocks!

danielbachhuber commented 7 years ago

👍 I dig the idea.

BE-Webdesign commented 7 years ago

👍 I dig the idea.

What are next steps?

schlessera commented 7 years ago

@danielbachhuber We should decide whether this should go into the existing, bundled scaffold command (alongside CPTs, taxonomies, etc...), or whether this should be a separate command that you can optionally install.

Given that this is an integral part of WordPress Core and that it seems to get more and more important for normal WP development, I'd go with a PR against wp-cli/scaffold-command to include it as a bundled command.

danielbachhuber commented 7 years ago

Given that this is an integral part of WordPress Core and that it seems to get more and more important for normal WP development, I'd go with a PR against wp-cli/scaffold-command to include it as a bundled command.

I agree with this.

@BE-Webdesign Can you share your proposed output for the routes?

BE-Webdesign commented 7 years ago

Can you share your proposed output for the routes?

I would have to think a bit about it first. I can make a gist.

BE-Webdesign commented 7 years ago

https://gist.github.com/BE-Webdesign/42df5e6117659b7bb8b5066ab4f1c90a

This would be a rough thing, I guess. It's not the full picture.

danielbachhuber commented 7 years ago

Ideally, it'd be functional code. What do you think about scaffolding individual routes instead, with command arguments for each of the features that register_rest_route() supports?

BE-Webdesign commented 7 years ago

Ideally, it'd be functional code. What do you think about scaffolding individual routes instead, with command arguments for each of the features that register_rest_route() supports?

That would probably be a better starting place, then we could create the controller scaffolding based on those outputs.