1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Cecil. |
5
|
|
|
* |
6
|
|
|
* (c) Arnaud Ligny <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Cecil\Command; |
15
|
|
|
|
16
|
|
|
use Cecil\Exception\RuntimeException; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
use Symfony\Component\Yaml\Yaml; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ShowConfig command. |
25
|
|
|
* |
26
|
|
|
* This command displays the website's configuration in YAML format. |
27
|
|
|
* It can be used to quickly review the current configuration settings. |
28
|
|
|
*/ |
29
|
|
|
class ShowConfig extends AbstractCommand |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->setName('show:config') |
38
|
|
|
->setDescription('Shows the configuration') |
39
|
|
|
->setDefinition([ |
40
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
41
|
|
|
new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Set the path to an extra configuration file'), |
42
|
|
|
]) |
43
|
|
|
->setHelp( |
44
|
|
|
<<<'EOF' |
45
|
|
|
The <info>%command.name%</> command shows the website\'s configuration in YAML format. |
46
|
|
|
|
47
|
|
|
<info>%command.full_name%</> |
48
|
|
|
<info>%command.full_name% path/to/the/working/directory</> |
49
|
|
|
|
50
|
|
|
To show the configuration with an extra configuration file, run: |
51
|
|
|
|
52
|
|
|
<info>%command.full_name% --config=config.yml</> |
53
|
|
|
EOF |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
* |
60
|
|
|
* @throws RuntimeException |
61
|
|
|
*/ |
62
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
63
|
|
|
{ |
64
|
|
|
try { |
65
|
|
|
$output->writeln($this->arrayToYaml($this->getBuilder()->getConfig()->export())); |
66
|
|
|
} catch (\Exception $e) { |
67
|
|
|
throw new RuntimeException($e->getMessage()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return 0; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Converts an array to YAML. |
75
|
|
|
*/ |
76
|
|
|
private function arrayToYaml(array $array): string |
77
|
|
|
{ |
78
|
|
|
return trim(Yaml::dump($array, 6, 2)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|