wp-cli/wp-cli — pull request #1535 by nyordanov (2014-12-02 22:03:53+00:00)
Title: Implement #522

*This implements `wp cli self-update`.*

I've reused the code for getting the url of the latest phar from `wp cli check-update`. A new `private function get_updates( $assoc_args )` is introduced which is used by both `check_update` and `self_update`.

An update is performed if all of these criteria are met:
* WP-CLI is used as a Phar
* The current Phar file is writable
* There is an available update
* The downloaded Phar can be executed (that is, the exit code of `php /path/to/downloaded/update --version` should be 0)
* The permissions of the downloaded file can be changed so that they match the permissions of the current Phar

-----

I haven't added any tests. However, in order to create a test for this command, it should be possible to set `WP_CLI_VERSION` at build time.

A manual test can be performed by decreasing `WP_CLI_VERSION` in [php/wp-cli.php](https://github.com/wp-cli/wp-cli/blob/master/php/wp-cli.php) and running this in a shell:

```
php -dphar.readonly=0 ./utils/make-phar.php /tmp/wp-cli.phar &&\
chmod +x /tmp/wp-cli.phar &&\
/tmp/wp-cli.phar cli self-update --yes &&\
/tmp/wp-cli.phar --version
```