4 * Contains \Drupal\Console\Command\Config\DeleteCommand.
7 namespace Drupal\Console\Command\State;
9 use Symfony\Component\Console\Input\InputArgument;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
14 use Drupal\Core\State\StateInterface;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
18 class DeleteCommand extends Command
28 * @var KeyValueFactoryInterface
33 * DeleteCommand constructor.
35 * @param StateInterface $state
36 * @param KeyValueFactoryInterface $keyValue
38 public function __construct(
39 StateInterface $state,
40 KeyValueFactoryInterface $keyValue
42 $this->state = $state;
43 $this->keyValue = $keyValue;
44 parent::__construct();
50 protected function configure()
53 ->setName('state:delete')
54 ->setDescription($this->trans('commands.state.delete.description'))
57 InputArgument::OPTIONAL,
58 $this->trans('commands.state.delete.arguments.name')
65 protected function interact(InputInterface $input, OutputInterface $output)
67 $io = new DrupalStyle($input, $output);
68 $name = $input->getArgument('name');
70 $names = array_keys($this->keyValue->get('state')->getAll());
71 $name = $io->choiceNoList(
72 $this->trans('commands.state.delete.arguments.name'),
75 $input->setArgument('name', $name);
82 protected function execute(InputInterface $input, OutputInterface $output)
84 $io = new DrupalStyle($input, $output);
85 $name = $input->getArgument('name');
87 $io->error($this->trans('commands.state.delete.messages.enter-name'));
92 if (!$this->state->get($name)) {
95 $this->trans('commands.state.delete.messages.state-not-exists'),
104 $this->state->delete($name);
105 } catch (\Exception $e) {
106 $io->error($e->getMessage());
113 $this->trans('commands.state.delete.messages.deleted'),