|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Bowerphp package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mauro D'Alatri <[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 Bowerphp\Output; |
|
13
|
|
|
|
|
14
|
|
|
use Bowerphp\Bowerphp; |
|
15
|
|
|
use Bowerphp\Package\PackageInterface; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
|
|
18
|
|
|
class BowerphpConsoleOutput |
|
19
|
|
|
{ |
|
20
|
|
|
protected $output; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param OutputInterface $output |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(OutputInterface $output) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->output = $output; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* writelnInfoPackage |
|
32
|
|
|
* |
|
33
|
|
|
* @param PackageInterface $package |
|
34
|
|
|
* @param string $action |
|
35
|
|
|
* @param string $message |
|
36
|
|
|
*/ |
|
37
|
|
|
public function writelnInfoPackage(PackageInterface $package, $action = '', $message = '') |
|
38
|
|
|
{ |
|
39
|
|
|
$this->output->writeln(sprintf('bower <info>%s</info> <fg=cyan>%s</fg=cyan> %s', |
|
40
|
|
|
str_pad($package->getName() . '#' . $package->getRequiredVersion(), 21, ' ', STR_PAD_RIGHT), |
|
41
|
|
|
str_pad($action, 10, ' ', STR_PAD_LEFT), |
|
42
|
|
|
$message |
|
43
|
|
|
)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* writelnInstalledPackage |
|
48
|
|
|
* |
|
49
|
|
|
* @param PackageInterface $package |
|
50
|
|
|
*/ |
|
51
|
|
|
public function writelnInstalledPackage(PackageInterface $package) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->output->writeln(sprintf('bower <info>%s</info> <fg=cyan>%s</fg=cyan>', |
|
54
|
|
|
str_pad($package->getName() . '#' . $package->getVersion(), 21, ' ', STR_PAD_RIGHT), |
|
55
|
|
|
str_pad('install', 10, ' ', STR_PAD_LEFT) |
|
56
|
|
|
)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* writelnNoBowerJsonFile |
|
61
|
|
|
*/ |
|
62
|
|
|
public function writelnNoBowerJsonFile() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->output->writeln(sprintf( |
|
65
|
|
|
'bower <info>%s</info> <fg=yellow>%s</fg=yellow> %s', |
|
66
|
|
|
str_pad('', 21, ' ', STR_PAD_RIGHT), |
|
67
|
|
|
str_pad('no-json', 10, ' ', STR_PAD_LEFT), |
|
68
|
|
|
'No bower.json file to save to, use bower init to create one' |
|
69
|
|
|
)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Rewrite json with colors and unescaped slashes |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $jsonString |
|
76
|
|
|
*/ |
|
77
|
|
|
public function writelnJson($jsonString) |
|
78
|
|
|
{ |
|
79
|
|
|
$keyColor = preg_replace('/"(\w+)": /', '<info>$1</info>: ', $jsonString); |
|
80
|
|
|
$valColor = preg_replace('/"([^"]+)"/', "<fg=cyan>'$1'</fg=cyan>", $keyColor); |
|
81
|
|
|
|
|
82
|
|
|
$this->output->writeln(stripslashes($valColor)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* writelnJson |
|
87
|
|
|
* |
|
88
|
|
|
* @param mixed $jsonPart |
|
89
|
|
|
*/ |
|
90
|
|
|
public function writelnJsonText($jsonPart) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->output->writeln(sprintf('<fg=cyan>%s</fg=cyan>', json_encode($jsonPart, JSON_PRETTY_PRINT))); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* writelnSearchOrLookup |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $name |
|
99
|
|
|
* @param string $homepage |
|
100
|
|
|
* @param int $pad |
|
101
|
|
|
*/ |
|
102
|
|
|
public function writelnSearchOrLookup($name, $homepage, $pad = 0) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->output->writeln(sprintf('%s<fg=cyan>%s</fg=cyan> %s', str_repeat(' ', $pad), $name, $homepage)); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* writelnListPackage |
|
109
|
|
|
* |
|
110
|
|
|
* @param PackageInterface $package |
|
111
|
|
|
* @param Bowerphp $bowerphp |
|
112
|
|
|
*/ |
|
113
|
|
|
public function writelnListPackage(PackageInterface $package, Bowerphp $bowerphp) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->output->writeln(sprintf('%s#%s<info>%s</info>', |
|
116
|
|
|
$package->getName(), |
|
117
|
|
|
$package->getVersion(), |
|
118
|
|
|
$bowerphp->isPackageExtraneous($package) ? ' extraneous' : '' |
|
119
|
|
|
)); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function writelnUpdatingPackage(PackageInterface $package) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->output->writeln(sprintf('bower <info>%s</info> <fg=cyan>%s</fg=cyan>', |
|
125
|
|
|
str_pad($package->getName() . '#' . $package->getRequiredVersion(), 21, ' ', STR_PAD_RIGHT), |
|
126
|
|
|
str_pad('install', 10, ' ', STR_PAD_LEFT) |
|
127
|
|
|
)); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|