1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 14:16:46 +02:00

feat(console): use args for EntriesCreateCommand #543

This commit is contained in:
Awilum
2021-09-20 23:47:29 +03:00
parent 3ce8bb091b
commit ac4b107f19

View File

@@ -10,10 +10,10 @@ declare(strict_types=1);
namespace Flextype\Console\Commands\Entries;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Input\InputArgument;
class EntriesCreateCommand extends Command
{
@@ -21,21 +21,21 @@ class EntriesCreateCommand extends Command
{
$this->setName('entries:create');
$this->setDescription('Create entry.');
$this->addOption('id', null, InputOption::VALUE_REQUIRED, 'Unique identifier of the entry.');
$this->addOption('data', null, InputOption::VALUE_OPTIONAL, 'Data to create for the entry.');
$this->addArgument('id', InputArgument::REQUIRED, 'Unique identifier of the entry.');
$this->addArgument('data', InputArgument::OPTIONAL, 'Data to create for the entry.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$data = $input->getOption('data') ? serializers()->json()->decode($input->getOption('data')) : [];
$data = $input->getArgument('data') ? serializers()->json()->decode($input->getArgument('data')) : [];
if (entries()->create($input->getOption('id'), $data)) {
$io->success('Entry ' . $input->getOption('id') . ' created.');
if (entries()->create($input->getArgument('id'), $data)) {
$io->success('Entry ' . $input->getArgument('id') . ' created.');
return Command::SUCCESS;
} else {
$io->error('Entry ' . $input->getOption('id') . ' wasn\'t created.');
$io->error('Entry ' . $input->getArgument('id') . ' wasn\'t created.');
return Command::FAILURE;
}
}