ToolCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Startwind\Forrest\CliCommand\Search;
4
5
use Startwind\Forrest\Output\OutputHelper;
6
use Symfony\Component\Console\Command\Command as SymfonyCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class ToolCommand extends SearchCommand
13
{
14
    public const COMMAND_NAME = 'search:tool';
15
16
    protected static $defaultName = self::COMMAND_NAME;
17
    protected static $defaultDescription = 'Search for commands that fit the given tool.';
18
19
    protected function configure(): void
20
    {
21
        parent::configure();
22
23
        $this->addArgument('tool', InputArgument::REQUIRED, 'The tool name you want to search for.');
24
        $this->addOption('force', null, InputOption::VALUE_NONE, 'Run the command without asking for permission.');
25
26
        $this->setAliases(['tool']);
27
    }
28
29
    protected function doExecute(InputInterface $input, OutputInterface $output): int
30
    {
31
        OutputHelper::renderHeader($output);
32
33
        $this->enrichRepositories();
34
35
        $tool = $input->getArgument('tool');
36
37
        $this->renderInfoBox('This is a list of commands that match the given tool.');
38
39
        $commands = $this->getRepositoryCollection()->searchByTools([$tool]);
40
41
        $toolInformation = $this->getRepositoryCollection()->getToolInformation($tool);
42
43
        if (count($toolInformation) > 0) {
44
            $output->writeln(['  Information about "<options=bold>' . $tool . '</>":', '']);
45
46
            foreach ($toolInformation as $repo => $information) {
47
                $output->writeln(\Startwind\Forrest\Util\OutputHelper::indentText($information->getDescription(), 0, 100, '  | '));
48
                if ($see = $information->getSee()) {
49
                    $output->writeln(['', '  For more information visit: <href=' . $see . '>' . $see . '</>', '']);
50
                }
51
            }
52
53
            $output->writeln('');
54
        }
55
56
        if (empty($commands)) {
57
            $this->renderErrorBox('No commands found that match the given tool.');
58
            return SymfonyCommand::FAILURE;
59
        }
60
61
        return $this->runFromCommands($commands);
62
    }
63
}
64