[CLI] php command to run PHP scripts
#2641
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation for the change, related issues
Adds a new CLI command called
phpthat can run PHP scripts using the PHP CLI SAPI.Try it locally as follows:
You should see:
The part after the double dash is the php command to run, in this case it's
php /wordpress/wp-cli.phar user listDiscussion
Developer experience
The command accepts all the same parameters as the
servercommand. This means two things:servercommand.Let's discuss how can we simplify the experience without adding implicit magic.
Paths
All the paths are VFS paths, see how I'm running
php /wordpress/wp-cli.pharand notphp ./wp-cli.phar. I'd love to be able to runphp ./wp-cli.phar --import-wxr=./wxr.xmland such – is there any sensible way of making it happen?Using only host paths isn't an option. The complete site directory structure only exists in VFS. I can't think of a portable way of re-creating
/wordpresson host. Even with native mounts in place, there may be 15 different mounts in VFS/wordpressthat are not there on host and that we cannot easily overlay on host.Mixing host paths and WordPress paths feels super risky. Imagine we magically had a way to resolve both
/wordpress/wp-cli.pharand/Users/adam/www/wp/wp-cli.phar. Are we better off in any way now? What'scwdand how do we calculate the path when wp-cli command refers to../imports/wxr.xml? What if both VFS and host have different files under that path? How wouldrenameetc. work?That leaves us with only one option – using only VFS paths like we would do in Docker. This complicates things for the package consumer – we need to train them to mount their PHP scripts and source data like they'd do with Docker.
Can anyone see any alternatives?
Auto-download wp-cli.phar
We could ship two commands:
phpthat lets you run any command, andwpthat downloads and runs wp-cli.phar specifically. That way we'd save folks from typing that same one mount every single time.cc @JanJakes @zaerl @brandonpayton @Jameswlepage @akirk