setName('backup:target:list') ->setDescription('List backup locations') ->addOption('test', 't', InputOption::VALUE_NONE, 'Also connect to each location and check the repository'); } protected function execute(InputInterface $input, OutputInterface $output): int { $rows = []; foreach ($this->targets->list() as $t) { $row = ['id' => $t->getId(), 'name' => $t->getName(), 'backend' => $t->getBackend(), 'path' => $t->getBasePath(), 'repository' => $t->getRepositoryId(), 'added' => date('Y-m-d H:i', $t->getCreatedAt())]; if ($input->getOption('test')) { try { $repo = $this->targets->repository($t); $row['status'] = 'ok, ' . count($repo->listSnapshots()) . ' snapshots'; } catch (\Throwable $e) { $row['status'] = 'error: ' . $e->getMessage(); } } $rows[] = $row; } if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { if ($rows === []) { $output->writeln('No backup locations yet (occ backup:target:add).'); return 0; } $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array_keys($rows[0]))->setRows(array_map('array_values', $rows))->render(); } else { $this->writeMixedInOutputFormat($input, $output, $rows); } return 0; } }