Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 067f2fc

Browse files
committed
Sort container profiles and add visual indicator while coosing the profile.
1 parent c7de082 commit 067f2fc

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

src/Command/Resources/ResourcesCommandBase.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function filterServices($services, InputInterface $input)
8181
$byType = [];
8282
foreach ($services as $name => $service) {
8383
$type = $service->type;
84-
list($prefix) = explode(':', $service->type, 2);
84+
[$prefix] = explode(':', $service->type, 2);
8585
$byType[$type][] = $name;
8686
$byType[$prefix][] = $name;
8787
}
@@ -156,4 +156,39 @@ protected function formatCPU($unformatted)
156156
{
157157
return sprintf('%.1f', $unformatted);
158158
}
159+
160+
/**
161+
* Format CPU Type.
162+
*
163+
* @param array|null $sizeInfo
164+
*
165+
* @return string
166+
*/
167+
protected function formatCPUType(array|null $sizeInfo): string
168+
{
169+
$size = $sizeInfo ? $sizeInfo['cpu'] : null;
170+
if ($size === null) {
171+
return "";
172+
}
173+
174+
return sprintf('(%s)', $sizeInfo['cpu_type']);
175+
}
176+
177+
/**
178+
* Sort container profiles by size.
179+
*
180+
* @param array $profiles
181+
*
182+
* @return array
183+
*/
184+
protected function sortContainerProfiles(array $profiles): array
185+
{
186+
foreach ($profiles as &$profile) {
187+
uasort($profile, function($a, $b) {
188+
return $a['cpu'] <=> (float)$b['cpu'];
189+
});
190+
}
191+
192+
return $profiles;
193+
}
159194
}

src/Command/Resources/ResourcesGetCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
$empty = $table->formatIsMachineReadable() ? '' : '<comment>not set</comment>';
8888
$notApplicable = $table->formatIsMachineReadable() ? '' : 'N/A';
8989

90-
$containerProfiles = $nextDeployment->container_profiles;
90+
$containerProfiles = $this->sortContainerProfiles($nextDeployment->container_profiles);
9191

9292
$rows = [];
9393
$cpuTypeOption = $input->getOption('cpu-type');

src/Command/Resources/ResourcesSetCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
135135
/** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
136136
$questionHelper = $this->getService('question_helper');
137137

138-
$containerProfiles = $nextDeployment->container_profiles;
138+
$containerProfiles = $this->sortContainerProfiles($nextDeployment->container_profiles);
139139

140140
// Remove guaranteed profiles if project does not support it.
141141
$supportsGuaranteedCPU = $this->api()->supportsGuaranteedCPU($nextDeployment->project_info);
@@ -203,13 +203,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
203203
|| (isset($properties['resources']['minimum']['memory']) && $sizeInfo['memory'] < $properties['resources']['minimum']['memory'])) {
204204
continue;
205205
}
206-
$description = sprintf('CPU %s, memory %s MB', $sizeInfo['cpu'], $sizeInfo['memory']);
206+
$description = sprintf('CPU %s, memory %s MB (%s)', $sizeInfo['cpu'], $sizeInfo['memory'], $sizeInfo['cpu_type']);
207207
if (isset($properties['resources']['profile_size'])
208208
&& $profileSize == $properties['resources']['profile_size']) {
209209
$description .= ' <question>(current)</question>';
210210
} elseif ($defaultOption !== null && $defaultOption === $profileSize) {
211211
$description .= ' <question>(default)</question>';
212212
}
213+
213214
$options[$profileSize] = $description;
214215
}
215216

@@ -410,8 +411,8 @@ private function summarizeChangesPerService($name, $service, array $updates, arr
410411
$newProperties = array_replace_recursive($properties, $updates);
411412
$newSizeInfo = $this->sizeInfo($newProperties, $containerProfiles);
412413
$this->stdErr->writeln(' CPU: ' . $this->formatChange(
413-
$this->formatCPU($sizeInfo ? $sizeInfo['cpu'] : null),
414-
$this->formatCPU($newSizeInfo['cpu'])
414+
$this->formatCPU($sizeInfo ? $sizeInfo['cpu'] : null) . ' ' . $this->formatCPUType($sizeInfo),
415+
$this->formatCPU($newSizeInfo['cpu']) . ' '. $this->formatCPUType($newSizeInfo)
415416
));
416417
$this->stdErr->writeln(' Memory: ' . $this->formatChange(
417418
$sizeInfo ? $sizeInfo['memory'] : null,

src/Command/Resources/ResourcesSizeListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5050
$servicesByProfile[$service->container_profile][] = $name;
5151
}
5252

53-
$containerProfiles = $nextDeployment->container_profiles;
53+
$containerProfiles = $this->sortContainerProfiles($nextDeployment->container_profiles);
5454

5555
if ($serviceOption = $input->getOption('service')) {
5656
if (!isset($services[$serviceOption])) {

0 commit comments

Comments
 (0)