Comments (5)
@danielbachhuber Overall the process was surprisingly easy, I liked how easy it was to create the subcommands and to document parameters within the code. The documentation is also very good, and I found almost everything I was looking for.
One small issue I ran into was that there is no way to pass the path
global parameter through with WP_CLI::run_command()
for commands other than wp core download
. This was easy to workaround by using WP_CLI::launch()
to launch the command directly in a new process and passing in the path there.
After downloading and testing out the command as a package, I'm realizing that there's no way to run custom subcommands globally without being in a WordPress installation or passing in the path to an existing one. It would be great to be able to create commands that can work outside of WordPress.
I also was hoping there would be an easy way to get WP-CLI config from the ~/.wp-cli/config.yaml
file, perhaps similar to how git config
works.
I managed to workaround this after realizing that you can store default args for any subcommand (even custom ones) in the ~/.wp-cli/config.yaml
file and grab the values from $assoc_args
.
So a wp cli config
command wasn't a necessity in my use-case, but could be helpful for other situations where global config is involved outside of subcommands.
from wp-installer.
Overall the process was surprisingly easy, I liked how easy it was to create the subcommands and to document parameters within the code. The documentation is also very good, and I found almost everything I was looking for.
Glad to hear!
One small issue I ran into was that there is no way to pass the path global parameter through with
WP_CLI::run_command()
for commands other than wp core download. This was easy to workaround by usingWP_CLI::launch()
to launch the command directly in a new process and passing in the path there.
You can actually get it from WP_CLI::get_config( 'path' );
. See https://wp-cli.org/docs/internal-api/wp-cli-get-config/
After downloading and testing out the command as a package, I'm realizing that there's no way to run custom subcommands globally without being in a WordPress installation or passing in the path to an existing one. It would be great to be able to create commands that can work outside of WordPress.
Are you aware of being able to use @when before_wp_load
in the command docs to have the command execute before WordPress loads? wp dist-archive
is one such example of a command that takes this approach: https://github.com/runcommand/dist-archive/blob/master/command.php#L45
I also was hoping there would be an easy way to get WP-CLI config from the
~/.wp-cli/config.yaml
file, perhaps similar to how git config works.
I'm not sure I follow. If WP_CLI::get_config()
doesn't do what you need it to, could you describe what you'd like to be able to do in a bit more detail?
from wp-installer.
You can actually get it from WP_CLI::get_config( 'path' );. See https://wp-cli.org/docs/internal-api/wp-cli-get-config/
Thanks for mentioning WP_CLI::get_config( 'path' )
. I wasn't aware of that function and it looks like it will be helpful for getting global WP-CLI configuration in custom CLI commands.
Is there a way to pass the path (or other config) retrieved from that function to core WP-CLI commands that are ran via WP_CLI::run_command()
?
Are you aware of being able to use @when before_wp_load in the command docs to have the command execute before WordPress loads?
Yes, after researching a bit further I took a similar approach. Being able to set the @when
directly in the subcommand code docs is helpful - I had passed it directly to WP_CLI::add_command()
.
I'm not sure I follow. If WP_CLI::get_config() doesn't do what you need it to, could you describe what you'd like to be able to do in a bit more detail?
WP_CLI::get_config()
should do the trick here, thanks again for the tip.
from wp-installer.
Is there a way to pass the path (or other config) retrieved from that function to core WP-CLI commands that are ran via
WP_CLI::run_command()
?
There isn't, because the idea is somewhat fraught conceptually.
--path=<path>
determines which WordPress instance WP-CLI should load when running a command. Because a command could be running within the scope of a loaded WordPress, supplying --path=<path>
via WP_CLI::run_command()
would either: not have an effect, or attempt to load another instance of WordPress again.
You can use WP_CLI::launch_self()
in this case. In the near future, I'd like to actually unify the two to create a more flexible single method, see wp-cli/wp-cli#3139
from wp-installer.
A 5 minute video may help newcomers.
from wp-installer.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-installer.