I'm trying to set up a some tooling in my .lando.yml file to rapidly accomplish several tasks I do on every fresh Wordpress install. Everything's working great except for if I try to use the [--extra-php]
option in the wp-cli and syntax as demonstrated in the wp-cli docs.
I get the following error when I run the command: /bin/sh: 1: Syntax error: "(" unexpected
If I remove the code beginning at <<PHP
and ending at the closing PHP
, everything executes perfectly.
I assume I need to escape the parentheses in some way, but how to properly do that in YAML? Though I don't specifically get a YAML, so I'm not sure if that's actually the issue either.
Relevant section of config: The error occurs at the first parenthesis.
tooling:
npm:
service: node
wp-install:
service: appserver
cmd:
- wp config create --dbname=wordpress --dbuser=wordpress --dbpass=wordpress --dbhost=database --extra-php <<'PHP'
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'ACF_PRO_LICENSE', 'XXX');
PHP
- wp core install --url=http://$LANDO_APP.$LANDO_DOMAIN --title=XXX --admin_user=StudioAl --admin_password=XXX --admin_email=kerri@studioal.com
- wp plugin install gravityformscli --activate
- wp gf install --XXX --activate
- wp plugin install "http://connect.advancedcustomfields.com/index.php?p=pro&a=download&k=XXX" --activate
Stock example of usage of the problem code in documentation for wp-cli, for reference
# Enable WP_DEBUG and WP_DEBUG_LOG
$ wp config create --dbname=testing --dbuser=wp --dbpass=securepswd --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
PHP
Success: Generated 'wp-config.php' file.
A YAML parser loads this:
- wp config create --dbname=wordpress --dbuser=wordpress --dbpass=wordpress --dbhost=database --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'ACF_PRO_LICENSE', 'XXX');
PHP
as a sequence with a single item that is a string which doesn't have any newlines. That is something like:
["wp config create --dbname=wordpress --dbuser=wordpress --dbpass=wordpress --dbhost=database --extra-php <<PHP define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'ACF_PRO_LICENSE', 'XXX'); PHP"]
If that string is handed to a (Unix) shell, it will IMO not interpret that as an heredoc because the delimiting identifier (PHP
) doesn't occur on a line of its own.
You might have more success if you make that scalar a literal style scalar by inserting a pipe symbol before the scalar:
- |
wp config create --dbname=wordpress --dbuser=wordpress --dbpass=wordpress --dbhost=database --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'ACF_PRO_LICENSE', 'XXX');
PHP
that way the string is loaded include the newlines (but without leading spaces)