setName($this->name)->setDescription($this->description); foreach ($this->getArguments() as $arguments) { call_user_func_array([$this, 'addArgument'], $arguments); } foreach ($this->getOptions() as $options) { call_user_func_array([$this, 'addOption'], $options); } } /** * Default implementation to get the arguments of this command. * * @return array */ public function getArguments() { return []; } /** * Default implementation to get the options of this command. * * @return array */ public function getOptions() { return []; } /** * Execute the command. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; return (int) $this->fire(); } /** * Get an argument from the input. * * @param string $key * * @return string */ public function argument($key) { return $this->input->getArgument($key); } /** * Get an option from the input. * * @param string $key * * @return string */ public function option($key) { return $this->input->getOption($key); } /** * Write a string as information output. * * @param string $string */ public function info($string) { $this->output->writeln("$string"); } /** * Write a string as comment output. * * @param string $string * @return void */ public function comment($string) { $this->output->writeln("$string"); } /** * Write a string as error output. * * @param string $string * @return void */ public function error($string) { $this->output->writeln("$string"); } /** * Format input to textual table. * * @param array $headers * @param \Illuminate\Contracts\Support\Arrayable|array $rows * @param string $style * @return void */ public function table(array $headers, $rows, $style = 'default') { $table = new Table($this->output); if ($rows instanceof Arrayable) { $rows = $rows->toArray(); } $table->setHeaders($headers)->setRows($rows)->setStyle($style)->render(); } /** * Ask the user the given question. * * @param string $question * * @return string */ public function ask($question) { $question = '' . $question . ' '; return $this->getHelperSet()->get('dialog')->ask($this->output, $question); } /** * Confirm the task with the user. * * @param string $task * @param string $question * * @return bool */ public function confirmTaskWithUser($task, $question) { $question = $question === true ? 'Are you sure you want to run the [' . $task . '] task?' : (string) $question; $question = '' . $question . ' [y/N]: '; return $this->getHelperSet()->get('dialog')->askConfirmation($this->output, $question, false); } /** * Ask the user the given secret question. * * @param string $question * * @return string */ public function secret($question) { $question = '' . $question . ' '; return $this->getHelperSet()->get('dialog')->askHiddenResponse($this->output, $question, false); } }