Created
February 6, 2021 19:01
-
-
Save tarlepp/1bdad27323d8a5f47e7e376a819be1a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Command; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Style\SymfonyStyle; | |
class JeremieCommand extends Command | |
{ | |
protected static $defaultName = 'jeremie'; | |
protected function configure() | |
{ | |
$this | |
->addOption('option', null, InputOption::VALUE_OPTIONAL, 'Option description') | |
; | |
} | |
protected function execute(InputInterface $input, OutputInterface $output): int | |
{ | |
$io = new SymfonyStyle($input, $output); | |
$option = $input->getOption('option'); | |
if (!$option) { | |
return Command::FAILURE; | |
} | |
switch ($option) { | |
case 'foo': | |
echo 'do foo'; | |
break; | |
case 'bar': | |
echo 'do bar'; | |
break; | |
default: | |
echo 'do default'; | |
break; | |
} | |
$io->success('You have a new command! Now make it your own! Pass --help to see your options.'); | |
return Command::SUCCESS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment