setName('config:preset') ->setDescription('Select a config preset') ->addArgument('preset', InputArgument::OPTIONAL, 'Preset to use for all unset config values', '') ->addOption('list', '', InputOption::VALUE_NONE, 'display available preset') ->addOption('compare', '', InputOption::VALUE_NONE, 'compare preset'); } protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('list')) { $this->getEnum('', $list); $this->writeArrayInOutputFormat($input, $output, $list); return self::SUCCESS; } if ($input->getOption('compare')) { $list = $this->presetManager->retrieveLexiconPreset(); if ($input->getOption('output') === 'plain') { $table = new Table($output); $table->setHeaders(['app', 'config', 'config key', 'value', ...array_map(static fn (ConfigLexiconPreset $p): string => $p->name, ConfigLexiconPreset::cases())]); foreach ($list as $appId => $entries) { foreach ($entries as $item) { $table->addRow([$appId, $item['config'], $item['entry']['key'], '' . ($item['value'] ?? '') . '', ...($item['defaults'] ?? [])]); } } $table->render(); return self::SUCCESS; } $this->writeArrayInOutputFormat($input, $output, $list); return self::SUCCESS; } $presetArg = $input->getArgument('preset'); if ($presetArg !== '') { $preset = $this->getEnum($presetArg, $list); if ($preset === null) { $output->writeln('Invalid preset: ' . $presetArg . ''); $output->writeln('Available presets: ' . implode(', ', $list)); return self::INVALID; } $this->presetManager->setLexiconPreset($preset); } $current = $this->presetManager->getLexiconPreset(); $this->writeArrayInOutputFormat($input, $output, [$current->name], 'current preset: '); return self::SUCCESS; } private function getEnum(string $name, ?array &$list = null): ?ConfigLexiconPreset { $list = []; foreach (ConfigLexiconPreset::cases() as $case) { $list[] = $case->name; if (strtolower($case->name) === strtolower($name)) { return $case; } } return null; } }