Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Created February 6, 2021 19:01
Show Gist options
  • Save tarlepp/1bdad27323d8a5f47e7e376a819be1a2 to your computer and use it in GitHub Desktop.
Save tarlepp/1bdad27323d8a5f47e7e376a819be1a2 to your computer and use it in GitHub Desktop.
<?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