2 namespace Consolidation\TestUtils;
4 use Consolidation\AnnotatedCommand\AnnotatedCommand;
6 use Symfony\Component\Console\Input\InputInterface;
7 use Symfony\Component\Console\Output\OutputInterface;
10 * Test file used in the Annotation Factory tests. It is also
11 * discovered in the testCommandDiscovery() test.
13 * The testCommandDiscovery test search base is the 'src' directory;
14 * any command files located immediately inside the search base are
15 * eligible for discovery, and will be included in the search results.
17 class ExampleAnnotatedCommand extends AnnotatedCommand
20 * Do the main function of the my:cat command.
22 public function myCat($one, $two = '', $multiple = [], $flip = false)
25 return "{$two}{$one}" . implode('', array_reverse($multiple));
27 return "{$one}{$two}" . implode('', $multiple);
31 * This is the my:cat command implemented as an AnnotatedCommand subclass.
33 * This command will concatenate two parameters. If the --flip flag
34 * is provided, then the result is the concatenation of two and one.
37 * @arg string $one The first parameter.
38 * @arg string $two The other parameter.
40 * @option array $multiple An array of values
41 * @default $multiple []
42 * @option boolean $flip Whether or not the second parameter should come first in the result.
44 * @usage bet alpha --flip
45 * Concatenate "alpha" and "bet".
47 protected function execute(InputInterface $input, OutputInterface $output)
49 $one = $input->getArgument('one');
50 $two = $input->getArgument('two');
51 $multiple = $input->getOption('multiple');
52 $flip = $input->getOption('flip');
54 $result = $this->myCat($one, $two, $multiple, $flip);
56 // We could also just use $output->writeln($result) here,
57 // but calling processResults enables the use of output
58 // formatters. Note also that if you use processResults, you
59 // should correctly inject the command processor into your
60 // annotated command via AnnotatedCommand::setCommandProcessor().
61 return $this->processResults($input, $output, $result);