1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Pickle |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* @license |
8
|
|
|
* |
9
|
|
|
* New BSD License |
10
|
|
|
* |
11
|
|
|
* Copyright © 2015-2015, Pickle community. All rights reserved. |
12
|
|
|
* |
13
|
|
|
* Redistribution and use in source and binary forms, with or without |
14
|
|
|
* modification, are permitted provided that the following conditions are met: |
15
|
|
|
* * Redistributions of source code must retain the above copyright |
16
|
|
|
* notice, this list of conditions and the following disclaimer. |
17
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
18
|
|
|
* notice, this list of conditions and the following disclaimer in the |
19
|
|
|
* documentation and/or other materials provided with the distribution. |
20
|
|
|
* * Neither the name of the Hoa nor the names of its contributors may be |
21
|
|
|
* used to endorse or promote products derived from this software without |
22
|
|
|
* specific prior written permission. |
23
|
|
|
* |
24
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
25
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
26
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
27
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
28
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
29
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
30
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
31
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
32
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
33
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
namespace Pickle\Console\Helper; |
38
|
|
|
|
39
|
|
|
use Composer\IO\ConsoleIO; |
40
|
|
|
use Pickle\Base\Interfaces; |
41
|
|
|
use Pickle\Package\Convey; |
42
|
|
|
use Symfony\Component\Console\Helper\Helper; |
43
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
44
|
|
|
use Symfony\Component\Console\Helper\Table; |
45
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
46
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
47
|
|
|
|
48
|
|
|
class PackageHelper extends Helper |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* Returns the canonical name of this helper. |
52
|
|
|
* |
53
|
|
|
* @return string The canonical name |
54
|
|
|
* |
55
|
|
|
* @api |
56
|
|
|
*/ |
57
|
|
|
public function getName() |
58
|
|
|
{ |
59
|
|
|
return 'package'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function showInfo(OutputInterface $output, Interfaces\Package $package) |
63
|
|
|
{ |
64
|
|
|
$table = new Table($output); |
65
|
|
|
$stability = $package->getStability(); |
66
|
|
|
$table |
67
|
|
|
->setRows([ |
68
|
|
|
['<info>Package name</info>', $package->getPrettyName()], |
69
|
|
|
['<info>Package version (current release)</info>', str_replace("-{$stability}", '', $package->getPrettyVersion())], |
70
|
|
|
['<info>Package status</info>', $stability], |
71
|
|
|
]) |
72
|
|
|
->render() |
73
|
|
|
; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function showOptions(OutputInterface $output, Interfaces\Package $package) |
77
|
|
|
{ |
78
|
|
|
$table = new Table($output); |
79
|
|
|
$table->setHeaders(['Type', 'Description', 'Default']); |
80
|
|
|
|
81
|
|
|
foreach ($package->getConfigureOptions() as $option) { |
82
|
|
|
$default = $option->default; |
83
|
|
|
|
84
|
|
|
if ($option->type === 'enable') { |
85
|
|
|
$option->type = '<fg=yellow>' . $option->type . '</fg=yellow>'; |
86
|
|
|
$default = $default ? '<fg=green>yes</fg=green>' : '<fg=red>no</fg=red>'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$table->addRow([ |
90
|
|
|
$option->type, |
91
|
|
|
wordwrap($option->prompt, 40, PHP_EOL), |
92
|
|
|
$default, |
93
|
|
|
]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$table->render(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param $path |
101
|
|
|
* |
102
|
|
|
* @return \Pickle\Base\Interfaces\Package |
103
|
|
|
*/ |
104
|
|
|
public function convey(InputInterface $input, OutputInterface $output, $path, $target = null) |
105
|
|
|
{ |
106
|
|
|
$helperSet = $this->getHelperSet(); |
107
|
|
|
$io = new ConsoleIO($input, $output, ($helperSet ?: new HelperSet())); |
108
|
|
|
|
109
|
|
|
$no_convert = $input->hasOption('no-convert') ? $input->getOption('no-convert') : false; |
110
|
|
|
if ($input->hasOption('version-override')) { |
111
|
|
|
$versionOverride = $input->getOption('version-override'); |
112
|
|
|
if ($versionOverride === null && $input->hasParameterOption('--version-override', true)) { |
113
|
|
|
$versionOverride = ''; |
114
|
|
|
} |
115
|
|
|
} else { |
116
|
|
|
$versionOverride = null; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return (new Convey($path, $io))->deliver($target, $no_convert, $versionOverride); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */ |
124
|
|
|
|