Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Last active February 6, 2021 19:32
Show Gist options
  • Save tarlepp/1319682337d3f32d1ec5958c6c4cc85d to your computer and use it in GitHub Desktop.
Save tarlepp/1319682337d3f32d1ec5958c6c4cc85d to your computer and use it in GitHub Desktop.
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
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 YsyncCommand extends Command
{
protected static $defaultName = 'ysync';
protected function configure()
{
$this
->addOption('data', null, InputOption::VALUE_REQUIRED, 'Data description')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
if (!$input->getOption('data')) {
$io->error('You need to give --data option with some value');
return 1;
}
$data = $input->getOption('data');
$io->title('This is your --data option value');
$io->info($data);
$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