From be88e09a595a17eddde3f056a87601ed3d28c802 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 13 Nov 2023 10:59:35 +0000 Subject: [PATCH] Default to size 0.5, disk 512 MB when setting resources --- src/Command/Resources/ResourcesSetCommand.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Command/Resources/ResourcesSetCommand.php b/src/Command/Resources/ResourcesSetCommand.php index 692e8032d..606b31444 100644 --- a/src/Command/Resources/ResourcesSetCommand.php +++ b/src/Command/Resources/ResourcesSetCommand.php @@ -156,7 +156,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $ensureHeader(); $new = isset($properties['resources']['profile_size']) ? 'a new' : 'a'; $profileSizes = $containerProfiles[$properties['container_profile']]; - $default = isset($properties['resources']['profile_size']) ? $properties['resources']['profile_size'] : null; $options = []; foreach ($profileSizes as $profileSize => $sizeInfo) { // Skip showing sizes that are below the minimum for this service. @@ -171,11 +170,21 @@ protected function execute(InputInterface $input, OutputInterface $output) } $options[$profileSize] = $description; } + + $defaultProfileSize = '0.5'; // TODO pick this from the API when exposed + if (isset($properties['resources']['profile_size'])) { + $defaultOption = $properties['resources']['profile_size']; + } elseif (isset($options[$defaultProfileSize])) { + $defaultOption = $defaultProfileSize; + } else { + $defaultOption = null; + } + if (!isset($properties['resources']['profile_size']) && empty($options)) { $this->stdErr->writeln(sprintf('No profile size can be found for the %s %s which satisfies its minimum resources.', $type, $name)); $errored = true; } else { - $profileSize = $questionHelper->chooseAssoc($options, sprintf('Choose %s profile size:', $new), $default, false, false); + $profileSize = $questionHelper->chooseAssoc($options, sprintf('Choose %s profile size:', $new), $defaultOption, false, false); if (!isset($properties['resources']['profile_size']) || $profileSize != $properties['resources']['profile_size']) { $updates[$group][$name]['resources']['profile_size'] = $profileSize; } @@ -212,7 +221,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } } elseif ($showCompleteForm || (empty($service->disk) && $input->isInteractive())) { $ensureHeader(); - $default = $service->disk; + $default = $service->disk ?: '512'; $diskSize = $questionHelper->askInput('Enter a disk size in MB', $default, ['512', '1024', '2048'], function ($v) use ($name, $service) { return $this->validateDiskSize($v, $name, $service); });