【问题标题】:Laravel artisan down with message parameter with spaces gives Too many arguments, expected arguments "command"Laravel 工匠使用带有空格的消息参数给出太多参数,预期参数“命令”
【发布时间】:2019-04-11 00:17:23
【问题描述】:

我经营工匠:

php artisan down --message "Going down for maintenance" --retry=60

[UPDATE] 或者像@Remul 建议的那样运行它:

php artisan down --message="Going down for maintenance" --retry=60

然后两者都给我错误:

[Symfony\Component\Console\Exception\RuntimeException]
 Too many arguments, expected arguments "command".

如果运行不带空格的命令:

php artisan down --message "Going_down_for_maintenance" --retry=60

没有错误发生

【问题讨论】:

  • 你可以试试用等号作为消息参数吗:php artisan down --message="Going down for maintenance" --retry=60
  • 我同意 Remul 的观点。没有等号,它会认为“停机维护”是另一种说法。如果您查看documentation,它会显示php artisan down --message="Upgrading Database" --retry=60
  • 没有工作给出同样的错误
  • @aynber 我注意到 symfony 代码有这个:public function __construct(array $argv = null, InputDefinition $definition = null) { if (null === $argv) { $argv = $_SERVER['argv']; } 问题在于全局,所以在 php 中

标签: php laravel symfony laravel-artisan


【解决方案1】:

我使用的是 php 7.0.14

我想通了:

问题实际上是 php 如何从命令行获取参数 在 vendor/symfony/console/Input/ArgvInput.php 我可以理解 php 得到这样的 argfuments:

0 => "artisan"
  1 => "down"
  2 => "--message=Going"
  3 => "down"
  4 => "for"
  5 => "maintenance"
  6 => "--retry=60"

所以为了确保我用这些内容制作了自己的脚本:

<?php

var_dump($argv);

然后我运行它:

php -v;php test_argv.php "parm with space" other_parameter

输出是:

PHP 7.0.14 (cli) (built: Jan 30 2017 15:45:33) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
array(5) {
  [0]=>
  string(13) "test_argv.php"
  [1]=>
  string(4) "parm"
  [2]=>
  string(4) "with"
  [3]=>
  string(5) "space"
  [4]=>
  string(15) "other_parameter"
}

我在其他机器上用不同版本的 PHP 运行它并查看我的结果:

PHP 7.1.5 (cli) (built: Sep 19 2017 10:48:01) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.5.4, Copyright (c) 2002-2017, by Derick Rethans
array(3) {
  [0] =>
  string(13) "test_argv.php"
  [1] =>
  string(15) "parm with space"
  [2] =>
  string(15) "other_parameter"
}

看起来在 php 7.0 和 7.1 的 argv 解析是完全不同的,一个忽略双引号作为字符串分隔符,而后者则不

【讨论】:

    【解决方案2】:

    这是一个不相关的问题,但这是谷歌发给我的地方,因为我犯了这个错误......所以......

    获得的另一个常见原因:

    Too many arguments, expected arguments "command".
    

    当工匠脚本需要一个选项时,您是否提供了一个参数。所以你需要改变

    ./artisan yourcommand:yoursubcommand some_kind_of_input
    

    ./artisan yourcommand:yoursubcommand --an_option=some_kind_of_input
    

    这个错误通常意味着 artisan 不希望这个命令有任何类型的附加参数...

    【讨论】:

      【解决方案3】:

      我有同样的问题,只需要使用反斜杠转义消息:

      php artisan down --message "Going\ down\ for\ maintenance" --retry=60
      

      【讨论】:

        【解决方案4】:

        此消息在 php artisan down 命令生成的名为 storage/framework/down 的 JSON 格式文件中可用。

        您可以打开该文件并对其进行修改。

        祝你好运

        【讨论】:

          猜你喜欢
          • 2020-03-23
          • 2020-03-27
          • 2019-08-14
          • 2015-11-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-04-14
          • 1970-01-01
          相关资源
          最近更新 更多