t6
4 years ago

[email protected] in 5.1

Posted 4 years ago by t6

Hi

Laravel 5.1 docs' artisan page does not mention the getOptions() function familiar from Laravel 5.0, yet the following console command throws an exception if the getOptions() function is commented out. Is this a mistake in the documentation or did I miss something when upgrading from 5.0 to 5.1? Command:

<?php namespace App\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;

class AwesomeCommand extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'commandname:commandsub {--kittens}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description =    'Delete & recreate indices {--force : do not ask for confirmation}';

    /**
     * Create a new command instance.
     *
     * @return \App\Console\Commands\AwesomeCommand
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        if ($this->option('kittens')) {
            $this->info('Kittens involved.');
            return;
        }

        $this->info('Kittens not involved.');
    }

//  /**
//   * Get the console command options.
//   *
//   * @return array
//   */
//  protected function getOptions()
//  {
//      return [
//          ['kittens', null, InputOption::VALUE_NONE, 'Do not ask for confirmation.'],
//      ];
//  }

}

Exception thrown when running php artisan commandname:commandsub --kittens:

[RuntimeException]
  The "--kittens" option does not exist.

Please sign in or create an account to participate in this conversation.