|
3 | 3 |
|
4 | 4 | use Platformsh\Cli\Command\CommandBase;
|
5 | 5 | use Platformsh\Cli\Console\ArrayArgument;
|
| 6 | +use Platformsh\Cli\Util\Wildcard; |
6 | 7 | use Platformsh\Client\Model\Environment;
|
7 | 8 | use Symfony\Component\Console\Input\InputArgument;
|
8 | 9 | use Symfony\Component\Console\Input\InputInterface;
|
@@ -60,7 +61,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
|
60 | 61 | }
|
61 | 62 | if ($specifiedEnvironmentIds) {
|
62 | 63 | $anythingSpecified = true;
|
63 |
| - $specifiedEnvironmentIds = $this->findEnvironmentIDsByWildcards($environments, $specifiedEnvironmentIds); |
| 64 | + $allIds = \array_map(function (Environment $e) { return $e->id; }, $environments); |
| 65 | + $specifiedEnvironmentIds = Wildcard::select($allIds, $specifiedEnvironmentIds); |
64 | 66 | $notFound = array_diff($specifiedEnvironmentIds, array_keys($environments));
|
65 | 67 | if (!empty($notFound)) {
|
66 | 68 | // Refresh the environments list if any environment is not found.
|
@@ -146,7 +148,8 @@ function ($environment) {
|
146 | 148 | // Exclude environment ID(s) specified in --exclude.
|
147 | 149 | $excludeIds = ArrayArgument::getOption($input, 'exclude');
|
148 | 150 | if (!empty($excludeIds)) {
|
149 |
| - $resolved = $this->findEnvironmentIdsByWildcards($selectedEnvironments, $excludeIds); |
| 151 | + $selectedIds = \array_map(function (Environment $e) { return $e->id; }, $selectedEnvironments); |
| 152 | + $resolved = Wildcard::select($selectedIds, $excludeIds); |
150 | 153 | if (count($resolved)) {
|
151 | 154 | $selectedEnvironments = \array_filter($selectedEnvironments, function (Environment $e) use ($resolved) {
|
152 | 155 | return !\in_array($e->id, $resolved, true);
|
@@ -234,25 +237,6 @@ function ($environment) {
|
234 | 237 | return $success ? 0 : 1;
|
235 | 238 | }
|
236 | 239 |
|
237 |
| - /** |
238 |
| - * Finds environments in a list matching a list of ID wildcards. |
239 |
| - * |
240 |
| - * @param Environment[] $environments |
241 |
| - * @param string[] $wildcards |
242 |
| - * |
243 |
| - * @return string[] |
244 |
| - */ |
245 |
| - private function findEnvironmentIDsByWildcards(array $environments, $wildcards) |
246 |
| - { |
247 |
| - $ids = \array_map(function (Environment $e) { return $e->id; }, $environments); |
248 |
| - $found = []; |
249 |
| - foreach ($wildcards as $wildcard) { |
250 |
| - $pattern = '/^' . str_replace('%', '.*', preg_quote($wildcard)) . '$/'; |
251 |
| - $found = array_merge($found, \preg_grep($pattern, $ids)); |
252 |
| - } |
253 |
| - return \array_unique($found); |
254 |
| - } |
255 |
| - |
256 | 240 | /**
|
257 | 241 | * @param array $toDeactivate
|
258 | 242 | * @param array $toDeleteBranch
|
|
0 commit comments