Skip to content

Commit

Permalink
Merge pull request #87 from wp-cli/70-generate-readme
Browse files Browse the repository at this point in the history
Dynamically generate README using `wp scaffold package-readme`
  • Loading branch information
danielbachhuber authored Jul 19, 2016
2 parents a70da04 + 07ec47b commit ca563c2
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 42 deletions.
181 changes: 141 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,160 @@
wp-rest-cli
===========
wp-cli/restful
==============

Unlock the potential of the WP REST API at the command line. Project backed by [Pressed](https://www.pressed.net/), [Chris Lema](https://chrislema.com/), [Human Made](https://hmn.md/), [Pagely](https://pagely.com/), [Pantheon](https://pantheon.io/) and many others. [Learn more →](http://wp-cli.org/restful/)
Unlock the potential of the WP REST API at the command line.

**Warning:** This project is at a very early stage. Treat it as an experiment, and understand that breaking changes will be made without warning. The sky may also fall on your head. Using wp-rest-cli requires the latest nightly build of [WP-CLI](http://wp-cli.org/), which you can install with `wp cli update --nightly`.
**Warning:** This project is at a very early stage. Treat it as an experiment, and understand that breaking changes will be made without warning. The sky may also fall on your head. Using RESTful WP-CLI requires the latest nightly build of [WP-CLI](http://wp-cli.org/), which you can install with `wp cli update --nightly`.

Project backed by [Pressed](https://www.pressed.net/), [Chris Lema](https://chrislema.com/), [Human Made](https://hmn.md/), [Pagely](https://pagely.com/), [Pantheon](https://pantheon.io/) and many others. [Learn more →](http://wp-cli.org/restful/)

[![Build Status](https://travis-ci.org/wp-cli/restful.svg?branch=master)](https://travis-ci.org/wp-cli/restful)

Quick links: [Overview](#overview) | [Installing](#installing) | [Contributing](#Contributing)
Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing)

## Using

RESTful WP-CLI makes [WP REST API](http://v2.wp-api.org/) endpoints available as [WP-CLI](http://wp-cli.org/) commands.

As WordPress becomes more of an application framework embedded into the web, RESTful WP-CLI enables WP-CLI users to interact with a given WordPress install through the higher-level, self-expressed abstraction of how WordPress understands itself. For instance, on an eCommerce website, instead of having to know data is stored as `wp post list --post_type=edd_product`, RESTful WP-CLI exposes the properly-modeled data at `wp rest product list`.

Here's an overview of how RESTful WP-CLI works, in two parts.

### 1. Auto-discovers WP REST API endpoints from any WordPress site running WordPress 4.4 or higher

Target a specific WordPress install with `--path=<path>`, `--ssh=<host>`, or `--http=<domain>`:

```
# The `--path=<path>` global parameter tells WP-CLI to interact with a WordPress install at a given path.
# Because this is a stock WordPress install, you see the posts, pages, and other resources you'd expect to see.
$ wp --path=/srv/www/wordpress-develop.dev/src rest
usage: wp rest attachment <command>
or: wp rest category <command>
or: wp rest comment <command>
or: wp rest page <command>
or: wp rest page-revision <command>
or: wp rest post <command>
or: wp rest post-revision <command>
or: wp rest status <command>
or: wp rest tag <command>
or: wp rest taxonomy <command>
or: wp rest type <command>
or: wp rest user <command>
# The `--http=<domain>` global parameter tells WP-CLI to auto-discover endpoints over HTTP.
# Because Wired has some custom post types, they're automatically registered as WP-CLI commands.
$ wp --http=www.wired.com rest
usage: wp rest attachment <command>
or: wp rest category <command>
or: wp rest comment <command>
or: wp rest liveblog <command>
or: wp rest liveblog-revision <command>
or: wp rest page <command>
or: wp rest page-revision <command>
or: wp rest podcast <command>
or: wp rest post <command>
or: wp rest post-revision <command>
or: wp rest series <command>
or: wp rest slack-channel <command>
or: wp rest status <command>
or: wp rest tag <command>
or: wp rest taxonomy <command>
or: wp rest type <command>
or: wp rest user <command>
or: wp rest video <command>
# The `--ssh=<host>` global parameter proxies command execution to a remote WordPress install.
# Because runcommand has a completely custom data model, you can only interact with commands, excerpts, and sparks.
$ wp --ssh=runcommand.io rest
usage: wp rest command <command>
or: wp rest excerpt <command>
or: wp rest spark <command>
```

### 2. Registers WP-CLI commands for the resource endpoints it understands, in the `wp rest` namespace.

In addition to the standard list, get, create, update and delete commands, RESTful WP-CLI also registers commands for higher-level operations like `edit`, `generate` and `diff`.

```
# In this example, `@wpdev` is a WP-CLI alias to `--path=/srv/www/wordpress-develop.dev/src`.
$ wp @wpdev rest user
usage: wp rest user create --username=<username> [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] --email=<email> [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] --password=<password> [--capabilities=<capabilities>] [--porcelain]
or: wp rest user delete <id> [--force=<force>] [--reassign=<reassign>] [--porcelain]
or: wp rest user diff <alias> [<resource>] [--fields=<fields>]
or: wp rest user edit <id>
or: wp rest user generate [--count=<count>] [--format=<format>] --username=<username> [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] --email=<email> [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] --password=<password> [--capabilities=<capabilities>] [--porcelain]
or: wp rest user get <id> [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>]
or: wp rest user list [--context=<context>] [--page=<page>] [--per_page=<per_page>] [--search=<search>] [--exclude=<exclude>] [--include=<include>] [--offset=<offset>] [--order=<order>] [--orderby=<orderby>] [--slug=<slug>] [--roles=<roles>] [--fields=<fields>] [--field=<field>] [--format=<format>]
or: wp rest user update <id> [--username=<username>] [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] [--email=<email>] [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] [--password=<password>] [--capabilities=<capabilities>] [--porcelain]
# Use `wp rest * edit` to open an existing item in the editor.
$ wp rest category edit 1 --user=daniel
---
description:
name: Uncategorized
slug: uncategorized
parent: 0
# Use `wp rest * generate` to generate dummy content.
$ wp @wpdev rest post generate --count=50 --title="Test Post" --user=daniel
Generating items 100% [==============================================] 0:01 / 0:02
# Use `wp rest * diff` to diff a resource or collection of resources between environments.
$ wp @dev-rest rest command diff @prod-rest find-unused-themes --fields=title
(-) http://runcommand.dev/api/ (+) https://runcommand.io/api/
command:
+ title: find-unused-themes
```

If WP-CLI is operating directly against a WordPress install, you can use the `--debug` flag to track the number of queries and total execution time. This can be useful for measuring and profiling API requests.

```
$ wp rest category list --debug
Debug (rest): REST command executed 3 queries in 0.000311 seconds. Use --debug=rest to see all queries. (1.118s)
+---------------+
| name |
+---------------+
| Test Category |
| Uncategorized |
+---------------+
```

There are many things RESTful WP-CLI can't yet do. Please [review the issue backlog](https://github.com/wp-cli/restful/issues), and open a new issue if you can't find an exising issue for your topic.

## Overview
## Installing

wp-rest-cli makes [WP REST API](http://v2.wp-api.org/) endpoints available as [WP-CLI](http://wp-cli.org/) commands. It does so by:
Installing this package requires WP-CLI 0.24.0-alpha or greater. Update to the latest nightly release with `wp cli update --nightly`.

* Auto-discovering WP REST API endpoints from any WordPress site running WordPress 4.4 or higher.
* Registering WP-CLI commands for the endpoints it understands.
Once you've done so, you can install this package with `wp package install wp-cli/restful`.

For example:
## Contributing

$ wp rest
usage: wp rest attachment <command>
or: wp rest category <command>
or: wp rest comment <command>
or: wp rest meta <command>
or: wp rest page <command>
or: wp rest pages-revision <command>
or: wp rest post <command>
or: wp rest posts-revision <command>
or: wp rest status <command>
or: wp rest tag <command>
or: wp rest taxonomy <command>
or: wp rest type <command>
or: wp rest user <command>
We appreciate you taking the initiative to contribute to this project.

$ wp --http=demo.wp-api.org rest tag get 65 --format=json
{
"id": 65,
"link": "http://demo.wp-api.org/tag/dolor-in-sunt-placeat-molestiae-ipsam/",
"name": "Dolor in sunt placeat molestiae ipsam",
"slug": "dolor-in-sunt-placeat-molestiae-ipsam",
"taxonomy": "post_tag"
}
Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Notice how you can use `--http=<domain>` to interact with a remote WordPress site. `--http=<domain>` must be supplied as the second argument to be used. Without it, wp-rest-cli will look for endpoints of a WordPress site in a directory specified by `--path=<path>` (or the current directory, if `--path=<path` isn't supplied).
### Reporting a bug

There are many things wp-rest-cli can't yet do. Please [review the issue backlog](https://github.com/wp-cli/restful/issues), and open a new issue if you can't find an exising issue for your topic.
Think you’ve found a bug? We’d love for you to help us get it fixed.

## Installing
Before you create a new issue, you should [search existing issues](https://github.com/wp-cli/restful/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

wp-rest-cli requires the latest nightly version of WP-CLI. Update with `wp cli update --nightly`.
Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/wp-cli/restful/issues/new) with the following:

Once you've done so, you can install wp-rest-cli with `wp package install wp-cli/restful`.
1. What you were doing (e.g. "When I run `wp post list`").
2. What you saw (e.g. "I see a fatal about a class being undefined.").
3. What you expected to see (e.g. "I expected to see the list of posts.")

wp-rest-cli also requires the [latest WP REST API beta](https://wordpress.org/plugins/rest-api/) installed and activated on whichever WordPress you'd like to interact with. Older betas are unsupported — please keep up to date.
Include as much detail as you can, and clear steps to reproduce if possible.

## Contributing
### Creating a pull request

Want to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/restful/issues/new) to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience:

1. Create a feature branch for each contribution.
2. Submit your pull request early for feedback.
3. Include functional tests with your changes. [Read the WP-CLI documentation](https://wp-cli.org/docs/pull-requests/#functional-tests) for an introduction.
4. Follow the [WordPress Coding Standards](http://make.wordpress.org/core/handbook/coding-standards/).

Code and ideas are more than welcome. Please [open an issue](https://github.com/wp-cli/restful/issues) with questions, feedback, and violent dissent. Pull requests are expected to include test coverage.
*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*
3 changes: 3 additions & 0 deletions bin/readme-stubs/installing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Installing this package requires WP-CLI 0.24.0-alpha or greater. Update to the latest nightly release with `wp cli update --nightly`.

Once you've done so, you can install this package with `wp package install wp-cli/restful`.
3 changes: 3 additions & 0 deletions bin/readme-stubs/package-description-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Warning:** This project is at a very early stage. Treat it as an experiment, and understand that breaking changes will be made without warning. The sky may also fall on your head. Using RESTful WP-CLI requires the latest nightly build of [WP-CLI](http://wp-cli.org/), which you can install with `wp cli update --nightly`.

Project backed by [Pressed](https://www.pressed.net/), [Chris Lema](https://chrislema.com/), [Human Made](https://hmn.md/), [Pagely](https://pagely.com/), [Pantheon](https://pantheon.io/) and many others. [Learn more →](http://wp-cli.org/restful/)
106 changes: 106 additions & 0 deletions bin/readme-stubs/using.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
RESTful WP-CLI makes [WP REST API](http://v2.wp-api.org/) endpoints available as [WP-CLI](http://wp-cli.org/) commands.

As WordPress becomes more of an application framework embedded into the web, RESTful WP-CLI enables WP-CLI users to interact with a given WordPress install through the higher-level, self-expressed abstraction of how WordPress understands itself. For instance, on an eCommerce website, instead of having to know data is stored as `wp post list --post_type=edd_product`, RESTful WP-CLI exposes the properly-modeled data at `wp rest product list`.

Here's an overview of how RESTful WP-CLI works, in two parts.

### 1. Auto-discovers WP REST API endpoints from any WordPress site running WordPress 4.4 or higher

Target a specific WordPress install with `--path=<path>`, `--ssh=<host>`, or `--http=<domain>`:

```
# The `--path=<path>` global parameter tells WP-CLI to interact with a WordPress install at a given path.
# Because this is a stock WordPress install, you see the posts, pages, and other resources you'd expect to see.
$ wp --path=/srv/www/wordpress-develop.dev/src rest
usage: wp rest attachment <command>
or: wp rest category <command>
or: wp rest comment <command>
or: wp rest page <command>
or: wp rest page-revision <command>
or: wp rest post <command>
or: wp rest post-revision <command>
or: wp rest status <command>
or: wp rest tag <command>
or: wp rest taxonomy <command>
or: wp rest type <command>
or: wp rest user <command>
# The `--http=<domain>` global parameter tells WP-CLI to auto-discover endpoints over HTTP.
# Because Wired has some custom post types, they're automatically registered as WP-CLI commands.
$ wp --http=www.wired.com rest
usage: wp rest attachment <command>
or: wp rest category <command>
or: wp rest comment <command>
or: wp rest liveblog <command>
or: wp rest liveblog-revision <command>
or: wp rest page <command>
or: wp rest page-revision <command>
or: wp rest podcast <command>
or: wp rest post <command>
or: wp rest post-revision <command>
or: wp rest series <command>
or: wp rest slack-channel <command>
or: wp rest status <command>
or: wp rest tag <command>
or: wp rest taxonomy <command>
or: wp rest type <command>
or: wp rest user <command>
or: wp rest video <command>
# The `--ssh=<host>` global parameter proxies command execution to a remote WordPress install.
# Because runcommand has a completely custom data model, you can only interact with commands, excerpts, and sparks.
$ wp --ssh=runcommand.io rest
usage: wp rest command <command>
or: wp rest excerpt <command>
or: wp rest spark <command>
```

### 2. Registers WP-CLI commands for the resource endpoints it understands, in the `wp rest` namespace.

In addition to the standard list, get, create, update and delete commands, RESTful WP-CLI also registers commands for higher-level operations like `edit`, `generate` and `diff`.

```
# In this example, `@wpdev` is a WP-CLI alias to `--path=/srv/www/wordpress-develop.dev/src`.
$ wp @wpdev rest user
usage: wp rest user create --username=<username> [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] --email=<email> [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] --password=<password> [--capabilities=<capabilities>] [--porcelain]
or: wp rest user delete <id> [--force=<force>] [--reassign=<reassign>] [--porcelain]
or: wp rest user diff <alias> [<resource>] [--fields=<fields>]
or: wp rest user edit <id>
or: wp rest user generate [--count=<count>] [--format=<format>] --username=<username> [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] --email=<email> [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] --password=<password> [--capabilities=<capabilities>] [--porcelain]
or: wp rest user get <id> [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>]
or: wp rest user list [--context=<context>] [--page=<page>] [--per_page=<per_page>] [--search=<search>] [--exclude=<exclude>] [--include=<include>] [--offset=<offset>] [--order=<order>] [--orderby=<orderby>] [--slug=<slug>] [--roles=<roles>] [--fields=<fields>] [--field=<field>] [--format=<format>]
or: wp rest user update <id> [--username=<username>] [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] [--email=<email>] [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] [--password=<password>] [--capabilities=<capabilities>] [--porcelain]
# Use `wp rest * edit` to open an existing item in the editor.
$ wp rest category edit 1 --user=daniel
---
description:
name: Uncategorized
slug: uncategorized
parent: 0
# Use `wp rest * generate` to generate dummy content.
$ wp @wpdev rest post generate --count=50 --title="Test Post" --user=daniel
Generating items 100% [==============================================] 0:01 / 0:02
# Use `wp rest * diff` to diff a resource or collection of resources between environments.
$ wp @dev-rest rest command diff @prod-rest find-unused-themes --fields=title
(-) http://runcommand.dev/api/ (+) https://runcommand.io/api/
command:
+ title: find-unused-themes
```

If WP-CLI is operating directly against a WordPress install, you can use the `--debug` flag to track the number of queries and total execution time. This can be useful for measuring and profiling API requests.

```
$ wp rest category list --debug
Debug (rest): REST command executed 3 queries in 0.000311 seconds. Use --debug=rest to see all queries. (1.118s)
+---------------+
| name |
+---------------+
| Test Category |
| Uncategorized |
+---------------+
```

There are many things RESTful WP-CLI can't yet do. Please [review the issue backlog](https://github.com/wp-cli/restful/issues), and open a new issue if you can't find an exising issue for your topic.
19 changes: 18 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-cli/restful",
"description": "Unlock the potential of the WP REST API at the command line",
"description": "Unlock the potential of the WP REST API at the command line.",
"license": "MIT",
"authors": [
{
Expand All @@ -15,5 +15,22 @@
"require": {},
"require-dev": {
"behat/behat": "~2.5"
},
"extras": {
"commands": [
"rest user list",
"rest user generate"
],
"readme": {
"package_description": {
"post": "bin/readme-stubs/package-description-post.md"
},
"using": {
"body": "bin/readme-stubs/using.md"
},
"installing": {
"body": "bin/readme-stubs/installing.md"
}
}
}
}
Loading

0 comments on commit ca563c2

Please sign in to comment.