wpengine / phpcompat

WordPress Plugin: PHP Compatibility Checker
https://wordpress.org/plugins/php-compatibility-checker/
120 stars 38 forks source link

Installing as a global wp-cli package? #163

Open robertmathews opened 7 years ago

robertmathews commented 7 years ago

This works fine for me via wp-cli when php-compatibility-checker is installed as a WordPress plugin on the site in question. However, I'd like to be able to run it even if not installed as a plugin on the site.

I tried installing it globally and it appears as a wp-cli package, but doesn't actually provide the command:

$ wp package install git://github.com/wpengine/phpcompat.git
Installing package wpengine/phpcompat (dev-master)
Updating /home/test/.wp-cli/packages/composer.json to require the package...
Registering git://github.com/wpengine/phpcompat.git as a VCS repository...
Using Composer to install the package...
---
[etc.]
---
Success: Package installed.

$ wp package list
+--------------------+-----------------+------------+--------+----------------+
| name               | authors         | version    | update | update_version |
+--------------------+-----------------+------------+--------+----------------+
| wpengine/phpcompat | Jason Stallings | dev-master | none   |                |
+--------------------+-----------------+------------+--------+----------------+

$ wp phpcompat 7.0
Error: 'phpcompat' is not a registered wp command. See 'wp help'.

Am I missing some way to do this? Or is it currently not possible?

jrfnl commented 7 years ago

Why not just install the underlying package in that case and run that ? After all, the plugin is not much more but a shell around it: https://github.com/wimg/phpcompatibility

robertmathews commented 7 years ago

Sure, that would work. But of course if you already use wp-cli and have it deployed, wp package install git://github.com/wpengine/phpcompat.git is simpler than installing https://github.com/wimg/phpcompatibility and PHP CodeSniffer separately.

I was mostly just surprised it didn't already work that way, and was wondering if it would be a trivial change to make it work by including the WP_CLI::add_command in the file autoloaded by composer.json.

octalmage commented 7 years ago

Hi @robertmathews! I honestly haven't tried that and I'm not sure what it would take. We include the WP-CLI command if WP_CLI is defined here:

https://github.com/wpengine/phpcompat/blob/master/wpengine-phpcompat.php#L17

I'm curious if this could be causing the breakdown. Here they use a different check:

https://github.com/wp-cli/scaffold-package-command/blob/master/templates/command.mustache#L1

I don't have too much time to dig into it at the moment but if it's something easy I'd be happy to deploy it.

robertmathews commented 7 years ago

I don't know much about Composer, unfortunately, but it seems that this line is never even called when run from wp-cli:

https://github.com/wpengine/phpcompat/blob/master/wpengine-phpcompat.php#L17

Comparing it to other packages, others seem to autoload the file that contains the "add_command", like:

https://github.com/wp-cli/scaffold-package-command/blob/master/composer.json#L21

I tried editing phpcompat's composer.json to do the same thing, which allows it to load "wpcli.php", but then it gives errors:

PHP Fatal error: require_once(): Failed opening required '/[...]/.wp-cli/packages/local/wpengine-phpcompat/src/../vendor/autoload.php' (include_path='.:/usr/share/php') in /[...]/.wp-cli/packages/local/wpengine-phpcompat/src/wpcli.php on line 2