addOption('check', null, InputOption::VALUE_NONE, 'Nur die Vorprüfung und die verfügbare Fassung zeigen.') ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Alles prüfen, aber nichts verändern.') ->addOption('to', null, InputOption::VALUE_REQUIRED, 'Ein bestimmter Tag, zum Beispiel v1.2.0.') ->addOption('maintenance', null, InputOption::VALUE_REQUIRED, 'Wartungszustand von Hand setzen: an oder aus.'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $switch = $input->getOption('maintenance'); if (null !== $switch) { if (!in_array($switch, ['an', 'aus'], true)) { $io->error('--maintenance erwartet „an“ oder „aus“.'); return Command::INVALID; } $this->updater->maintenance('an' === $switch); $io->success(sprintf('Wartungszustand ist %s.', 'an' === $switch ? 'eingeschaltet – die Website antwortet mit 503' : 'aufgehoben')); return Command::SUCCESS; } $state = $this->updater->state(); $io->definitionList( ['Fassung' => $state['version']], ['Stand' => $state['describe'].' ('.$state['commit'].')'], ['Wartung' => $state['maintenance'] ? 'eingeschaltet' : 'aus'], ); $checks = $this->updater->check(); $io->table(['Prüfung', '', 'Befund'], array_map( static fn (array $check): array => [$check['name'], $check['ok'] ? 'ok' : 'FEHLT', $check['detail']], $checks, )); $failed = array_values(array_filter($checks, static fn (array $check): bool => !$check['ok'])); if ($input->getOption('check')) { $available = $this->updater->availableVersion(); $io->writeln(sprintf('Verfügbar: %s', $available ?? 'kein Tag der Form v1.2.3 gefunden')); return [] === $failed ? Command::SUCCESS : Command::FAILURE; } if ([] !== $failed) { $io->error('Die Vorprüfung ist nicht bestanden; es wird nichts verändert.'); return Command::FAILURE; } $target = $input->getOption('to'); $result = $this->updater->update(is_string($target) ? $target : null, (bool) $input->getOption('dry-run')); foreach ($result['steps'] as $step) { $io->writeln(sprintf('%s %s: %s', $step['ok'] ? ' ok ' : ' FEHLER', $step['step'], $step['detail'])); } if ($result['ok']) { $io->success(sprintf('Update auf %s abgeschlossen.', $result['target'] ?? 'die aktuelle Fassung')); return Command::SUCCESS; } $io->error('Das Update ist gescheitert. Die Schritte oben sagen, wo.'); return Command::FAILURE; } }