当用户输入错误的参数时,重定向命令输出以帮助

时间:2016-07-04 07:42:56

标签: laravel laravel-5.2

当用户传递错误数量的参数或错误的参数选项不正确时,从Symfony组件中获取错误。

php artisan migratedb:migrate acct --tables=pepe

  [Symfony\Component\Console\Exception\RuntimeException]  
  The "--tables" option does not exist.    

可能会出现重定向错误以帮助改变?

php artisan migratedb:migrate acct --tables=pepe

Usage:
  migratedb:migrate [options] [--] <type>

Arguments:
  type                  full|table

Options:
      --table[=TABLE]    (multiple values allowed)
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under.
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
 Migrate all o one table from setdart_oscom

编辑代码以获得更多解释:

...
protected $signature = 'migratedb:migrate 
                            {type : full|table}
                            {--table=*}';

public function fire()
{
        // Check arguments
        $this->checkArguments();
}

private function checkArguments()
{
        $type  = $this->argument('type');
        $table = $this->option('table');

        if (empty($table)) {
            echo "You must specify at least one table.".PHP_EOL;
            echo "Use: php artisan migratedb:migrate --help".PHP_EOL;
            //Artisan::call('migratedb:migrate', array('-h'=>true)); // NOT WORK
            exit;
        }

0 个答案:

没有答案