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\Util; |
13
|
|
|
|
14
|
|
|
use Puli\Manager\Api\Package\PackageCollection; |
15
|
|
|
use Webmozart\Console\Api\Args\Args; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Utilities for inspecting {@link Args} instances. |
19
|
|
|
* |
20
|
|
|
* @since 1.0 |
21
|
|
|
* |
22
|
|
|
* @author Bernhard Schussek <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ArgsUtil |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Returns the packages selected in the console arguments. |
28
|
|
|
* |
29
|
|
|
* @param Args $args The console arguments. |
30
|
|
|
* @param PackageCollection $packages The available packages. |
31
|
|
|
* |
32
|
|
|
* @return string[] The package names. |
33
|
|
|
*/ |
34
|
36 |
|
public static function getPackageNames(Args $args, PackageCollection $packages) |
35
|
|
|
{ |
36
|
|
|
// Display all packages if "all" is set |
37
|
36 |
|
if ($args->isOptionSet('all')) { |
38
|
|
|
return $packages->getPackageNames(); |
39
|
|
|
} |
40
|
|
|
|
41
|
36 |
|
$packageNames = array(); |
42
|
|
|
|
43
|
36 |
|
if ($args->isOptionSet('root')) { |
44
|
9 |
|
$packageNames[] = $packages->getRootPackage()->getName(); |
45
|
|
|
} |
46
|
|
|
|
47
|
36 |
|
foreach ($args->getOption('package') as $packageName) { |
48
|
12 |
|
$packageNames[] = $packageName; |
49
|
|
|
} |
50
|
|
|
|
51
|
36 |
|
return $packageNames ?: $packages->getPackageNames(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the non-root packages selected in the console arguments. |
56
|
|
|
* |
57
|
|
|
* @param Args $args The console arguments. |
58
|
|
|
* @param PackageCollection $packages The available packages. |
59
|
|
|
* |
60
|
|
|
* @return string[] The package names. |
61
|
|
|
*/ |
62
|
|
|
public static function getPackageNamesWithoutRoot(Args $args, PackageCollection $packages) |
63
|
|
|
{ |
64
|
|
|
// Display all packages if "all" is set |
65
|
|
|
if ($args->isOptionSet('all')) { |
66
|
|
|
return $packages->getInstalledPackageNames(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$packageNames = array(); |
70
|
|
|
|
71
|
|
|
foreach ($args->getOption('package') as $packageName) { |
72
|
|
|
$packageNames[] = $packageName; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $packageNames ?: $packages->getInstalledPackageNames(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function __construct() |
79
|
|
|
{ |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|