|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Startwind\Forrest\CliCommand\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Startwind\Forrest\Util\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\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class ExplainCommand extends CommandCommand |
|
12
|
|
|
{ |
|
13
|
|
|
protected static $defaultName = 'commands:explain'; |
|
14
|
|
|
protected static $defaultDescription = 'Show a specific command. It will not run it.'; |
|
15
|
|
|
|
|
16
|
|
|
protected function configure(): void |
|
17
|
|
|
{ |
|
18
|
|
|
parent::configure(); |
|
19
|
|
|
$this->addArgument('identifier', InputArgument::REQUIRED, 'The commands identifier.'); |
|
20
|
|
|
$this->setAliases(['explain']); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function doExecute(InputInterface $input, OutputInterface $output): int |
|
24
|
|
|
{ |
|
25
|
|
|
$this->enrichRepositories(); |
|
26
|
|
|
|
|
27
|
|
|
$commandIdentifier = $input->getArgument('identifier'); |
|
28
|
|
|
|
|
29
|
|
|
$command = $this->getCommand($commandIdentifier); |
|
30
|
|
|
|
|
31
|
|
|
OutputHelper::writeInfoBox($output, [ |
|
32
|
|
|
'Explanation of "' . $commandIdentifier . '":' |
|
33
|
|
|
]); |
|
34
|
|
|
|
|
35
|
|
|
$output->writeln([$command->getPrompt(), ""]); |
|
36
|
|
|
|
|
37
|
|
|
$explanation = OutputHelper::indentText($command->getExplanation(), 2, 80, ' |'); |
|
38
|
|
|
|
|
39
|
|
|
$output->writeln($explanation); |
|
40
|
|
|
$output->writeln([ |
|
41
|
|
|
'', |
|
42
|
|
|
'To run this command type: ', |
|
43
|
|
|
'', |
|
44
|
|
|
'forrest run ' . $commandIdentifier, |
|
45
|
|
|
'', |
|
46
|
|
|
]); |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
return SymfonyCommand::SUCCESS; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|