ToolCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
eloc 25
dl 0
loc 50
rs 10
c 5
b 1
f 1
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doExecute() 0 33 5
A configure() 0 8 1
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