setName('backend:search:id') ->setDescription('Get backend metadata related to specific id.') ->addOption('include-raw-response', null, InputOption::VALUE_NONE, 'Include unfiltered raw response.') ->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Use Alternative config file.') ->addArgument('backend', InputArgument::REQUIRED, 'Backend name.') ->addArgument('id', InputArgument::REQUIRED, 'Item id.'); } protected function runCommand(InputInterface $input, OutputInterface $output): int { $mode = $input->getOption('output'); $id = $input->getArgument('id'); // -- Use Custom servers.yaml file. if (($config = $input->getOption('config'))) { try { Config::save('servers', Yaml::parseFile($this->checkCustomServersFile($config))); } catch (RuntimeException $e) { $arr = [ 'error' => $e->getMessage() ]; $this->displayContent('table' === $mode ? [$arr] : $arr, $output, $mode); return self::FAILURE; } } try { $backend = $this->getBackend($input->getArgument('backend')); $opts = []; if ($input->getOption('include-raw-response')) { $opts[Options::RAW_RESPONSE] = true; } $results = $backend->searchId(id: $id, opts: $opts); if (count($results) < 1) { $arr = [ 'info' => sprintf('%s: No results were found for this id #\'%s\' .', $backend->getName(), $id), ]; $this->displayContent('table' === $mode ? [$arr] : $arr, $output, $mode); return self::FAILURE; } $this->displayContent('table' === $mode ? [$results] : $results, $output, $mode); return self::SUCCESS; } catch (RuntimeException $e) { $arr = [ 'error' => $e->getMessage(), ]; if ('table' !== $mode) { $arr += [ 'file' => $e->getFile(), 'line' => $e->getLine(), ]; } $this->displayContent('table' === $mode ? [$arr] : $arr, $output, $mode); return self::FAILURE; } } }