Lando工具命令语法

huangapple go评论88阅读模式
英文:

Lando tooling command syntax

问题

我尝试在我的 .lando.yml 文件中设置一些工具,以便在每次安装新的 WordPress 时能够快速完成多项任务。一切都运行得很顺利,除非我尝试在 wp-cli 中使用 [--extra-php] 选项以及在 wp-cli 文档中演示的语法。

当我运行命令时,出现以下错误:/bin/sh: 1: Syntax error: "unexpected"

如果我删除从 <<PHP 开始到闭合的 PHP 结束的代码部分,一切都可以正常执行。

我认为我需要以某种方式转义括号,但如何在 YAML 中正确地执行这样的操作呢?尽管我没有明确收到 YAML 错误,所以我不确定这是否真的是问题所在。

配置文件的相关部分:
错误出现在第一个括号处。

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

wp-cli 文档中用于参考的问题代码的示例用法

# 启用 WP_DEBUG 和 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: 生成了 'wp-config.php' 文件。
英文:

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.

答案1

得分: 1

一个YAML解析器加载这个内容:

- 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 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"]

如果将该字符串传递给Unix shell,我认为它不会将其解释为heredoc,因为分隔标识符 (PHP) 不会单独出现在一行上。

如果您希望更成功地将该标量解释为字面样式标量,请在标量之前插入一个管道符号:

- |
  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  

这样加载字符串将包括换行符(但没有前导空格)。

英文:

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)

huangapple
  • 本文由 发表于 2023年7月18日 09:29:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定