mirror of
https://github.com/flextype/flextype.git
synced 2025-08-10 07:06:45 +02:00
feat(console): add EntriesDeleteCommand #543
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
class EntriesDeleteCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName('entries:delete');
|
||||
$this->setDescription('Delete entry.');
|
||||
$this->addOption('id', null, InputOption::VALUE_REQUIRED, 'Unique identifier of the entry.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
if (entries()->delete($input->getOption('id'), $data)) {
|
||||
$io->success('Deleted entry ' . $input->getOption('id'));
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
$io->error('Entry ' . $input->getOption('id') . ' wasn\'t deleted.');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,7 +11,9 @@ namespace Flextype;
|
||||
|
||||
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||
use Flextype\Console\Commands\Entries\EntriesCreateCommand;
|
||||
use Flextype\Console\Commands\Entries\EntriesDeleteCommand;
|
||||
|
||||
$app = new ConsoleApplication();
|
||||
$app->add(new EntriesCreateCommand());
|
||||
$app->run();
|
||||
$console = new ConsoleApplication();
|
||||
$console->add(new EntriesCreateCommand());
|
||||
$console->add(new EntriesDeleteCommand());
|
||||
$console->run();
|
Reference in New Issue
Block a user