1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/cli package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[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
|
|
|
namespace Puli\Cli\Handler; |
13
|
|
|
|
14
|
|
|
use Puli\Cli\Style\PuliTableStyle; |
15
|
|
|
use Puli\Cli\Util\StringUtil; |
16
|
|
|
use Puli\Manager\Api\Package\RootPackageFileManager; |
17
|
|
|
use Webmozart\Console\Api\Args\Args; |
18
|
|
|
use Webmozart\Console\Api\IO\IO; |
19
|
|
|
use Webmozart\Console\UI\Component\Table; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Handles the "config" command. |
23
|
|
|
* |
24
|
|
|
* @since 1.0 |
25
|
|
|
* |
26
|
|
|
* @author Bernhard Schussek <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class ConfigCommandHandler |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var RootPackageFileManager |
32
|
|
|
*/ |
33
|
|
|
private $manager; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Creates the handler. |
37
|
|
|
* |
38
|
|
|
* @param RootPackageFileManager $manager The root package file manager. |
39
|
|
|
*/ |
40
|
|
|
public function __construct(RootPackageFileManager $manager) |
41
|
|
|
{ |
42
|
|
|
$this->manager = $manager; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Handles the "config" command. |
47
|
|
|
* |
48
|
|
|
* @param Args $args The console arguments. |
49
|
|
|
* @param IO $io The I/O. |
50
|
|
|
* |
51
|
|
|
* @return int The status code. |
52
|
|
|
*/ |
53
|
|
|
public function handleList(Args $args, IO $io) |
54
|
|
|
{ |
55
|
|
|
$raw = !$args->isOptionSet('parsed'); |
56
|
|
|
$userValues = $this->manager->getConfigKeys(false, false, $raw); |
57
|
|
|
$effectiveValues = $this->manager->getConfigKeys(true, true, $raw); |
58
|
|
|
|
59
|
|
|
$table = new Table(PuliTableStyle::borderless()); |
60
|
|
|
$table->setHeaderRow(array('Config Key', 'User Value', 'Effective Value')); |
61
|
|
|
|
62
|
|
|
foreach ($effectiveValues as $key => $value) { |
63
|
|
|
$table->addRow(array( |
64
|
|
|
sprintf('<c1>%s</c1>', $key), |
65
|
|
|
array_key_exists($key, $userValues) |
66
|
|
|
? StringUtil::formatValue($userValues[$key], false) |
67
|
|
|
: '', |
68
|
|
|
StringUtil::formatValue($value, false), |
69
|
|
|
)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$table->render($io); |
73
|
|
|
|
74
|
|
|
return 0; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Handles the "config <key>" command. |
79
|
|
|
* |
80
|
|
|
* @param Args $args The console arguments. |
81
|
|
|
* @param IO $io The I/O. |
82
|
|
|
* |
83
|
|
|
* @return int The status code. |
84
|
|
|
*/ |
85
|
|
|
public function handleShow(Args $args, IO $io) |
86
|
|
|
{ |
87
|
|
|
$raw = !$args->isOptionSet('parsed'); |
88
|
|
|
$value = $this->manager->getConfigKey($args->getArgument('key'), null, true, $raw); |
89
|
|
|
|
90
|
|
|
$io->writeLine(StringUtil::formatValue($value, false)); |
91
|
|
|
|
92
|
|
|
return 0; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Handles the "config <key> <value>" command. |
97
|
|
|
* |
98
|
|
|
* @param Args $args The console arguments. |
99
|
|
|
* |
100
|
|
|
* @return int The status code. |
101
|
|
|
*/ |
102
|
|
|
public function handleSet(Args $args) |
103
|
|
|
{ |
104
|
|
|
$value = StringUtil::parseValue($args->getArgument('value')); |
105
|
|
|
|
106
|
|
|
$this->manager->setConfigKey($args->getArgument('key'), $value); |
107
|
|
|
|
108
|
|
|
return 0; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Handles the "config -r <key>" command. |
113
|
|
|
* |
114
|
|
|
* @param Args $args The console arguments. |
115
|
|
|
* |
116
|
|
|
* @return int The status code. |
117
|
|
|
*/ |
118
|
|
|
public function handleReset(Args $args) |
119
|
|
|
{ |
120
|
|
|
$this->manager->removeConfigKey($args->getArgument('key')); |
121
|
|
|
|
122
|
|
|
return 0; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|