1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of web-stack |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Slick\WebStack\UserInterface\Console; |
13
|
|
|
|
14
|
|
|
use Slick\ModuleApi\Infrastructure\SlickModuleInterface; |
15
|
|
|
use Slick\WebStack\Infrastructure\Exception\InvalidModuleName; |
16
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
17
|
|
|
use Symfony\Component\Console\Command\Command; |
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* DescribeModuleCommand |
25
|
|
|
* |
26
|
|
|
* @package Slick\WebStack\Infrastructure |
27
|
|
|
*/ |
28
|
|
|
#[AsCommand( |
29
|
|
|
name: 'modules:describe', |
30
|
|
|
description: 'Explains the functionality of a module.', |
31
|
|
|
aliases: ['describe'] |
32
|
|
|
)] |
33
|
|
|
class DescribeModuleCommand extends Command |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
use ModuleCommandTrait; |
37
|
|
|
|
38
|
|
|
protected string $appRoot; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
protected string $moduleListFile; |
42
|
|
|
|
43
|
|
|
protected ?SymfonyStyle $outputStyle = null; |
44
|
|
|
|
45
|
|
|
public function __construct(string $appRoot) |
46
|
|
|
{ |
47
|
|
|
parent::__construct(); |
48
|
|
|
$this->appRoot = $appRoot; |
49
|
|
|
$this->moduleListFile = $this->appRoot . EnableModuleCommand::ENABLED_MODULES_FILE; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function configure(): void |
53
|
|
|
{ |
54
|
|
|
$this->addArgument('module', InputArgument::REQUIRED, "Module name to describe"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
58
|
|
|
{ |
59
|
|
|
$this->outputStyle = new SymfonyStyle($input, $output); |
60
|
|
|
$moduleName = $input->getArgument('module'); |
61
|
|
|
try { |
62
|
|
|
$retrieveModuleName = $this->retrieveModuleName($moduleName); |
63
|
|
|
} catch (InvalidModuleName $exception) { |
64
|
|
|
$this->outputStyle->writeln( |
65
|
|
|
"<error>{$exception->getMessage()}</error>" |
66
|
|
|
); |
67
|
|
|
return Command::FAILURE; |
68
|
|
|
} |
69
|
|
|
/** @var SlickModuleInterface $module */ |
70
|
|
|
$module = new $retrieveModuleName(); |
71
|
|
|
|
72
|
|
|
$this->renderTable([$module], $this->outputStyle); |
73
|
|
|
return Command::SUCCESS; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|