4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Definition\Cli;
13 use Behat\Behat\Definition\DefinitionWriter;
14 use Behat\Behat\Definition\Printer\ConsoleDefinitionInformationPrinter;
15 use Behat\Behat\Definition\Printer\ConsoleDefinitionListPrinter;
16 use Behat\Behat\Definition\Printer\DefinitionPrinter;
17 use Behat\Testwork\Cli\Controller;
18 use Behat\Testwork\Suite\SuiteRepository;
19 use Symfony\Component\Console\Command\Command;
20 use Symfony\Component\Console\Input\InputInterface;
21 use Symfony\Component\Console\Input\InputOption;
22 use Symfony\Component\Console\Output\OutputInterface;
25 * Shows all currently available definitions to the user.
27 * @author Konstantin Kudryashov <ever.zet@gmail.com>
29 final class AvailableDefinitionsController implements Controller
32 * @var SuiteRepository
34 private $suiteRepository;
36 * @var DefinitionWriter
40 * @var ConsoleDefinitionListPrinter
44 * @var ConsoleDefinitionInformationPrinter
49 * Initializes controller.
51 * @param SuiteRepository $suiteRepository
52 * @param DefinitionWriter $writer
53 * @param ConsoleDefinitionListPrinter $listPrinter
54 * @param ConsoleDefinitionInformationPrinter $infoPrinter
56 public function __construct(
57 SuiteRepository $suiteRepository,
58 DefinitionWriter $writer,
59 ConsoleDefinitionListPrinter $listPrinter,
60 ConsoleDefinitionInformationPrinter $infoPrinter
62 $this->suiteRepository = $suiteRepository;
63 $this->writer = $writer;
64 $this->listPrinter = $listPrinter;
65 $this->infoPrinter = $infoPrinter;
71 public function configure(Command $command)
73 $command->addOption('--definitions', '-d', InputOption::VALUE_REQUIRED,
74 "Print all available step definitions:" . PHP_EOL .
75 "- use <info>--definitions l</info> to just list definition expressions." . PHP_EOL .
76 "- use <info>--definitions i</info> to show definitions with extended info." . PHP_EOL .
77 "- use <info>--definitions 'needle'</info> to find specific definitions." . PHP_EOL .
78 "Use <info>--lang</info> to see definitions in specific language."
85 public function execute(InputInterface $input, OutputInterface $output)
87 if (null === $argument = $input->getOption('definitions')) {
91 $printer = $this->getDefinitionPrinter($argument);
92 foreach ($this->suiteRepository->getSuites() as $suite) {
93 $this->writer->printSuiteDefinitions($printer, $suite);
100 * Returns definition printer for provided option argument.
102 * @param string $argument
104 * @return DefinitionPrinter
106 private function getDefinitionPrinter($argument)
108 if ('l' === $argument) {
109 return $this->listPrinter;
112 if ('i' !== $argument) {
113 $this->infoPrinter->setSearchCriterion($argument);
116 return $this->infoPrinter;