Skip to content

Commit 2506976

Browse files
committed
fix: cache:modify command also needs new formatted cache type descriptions
1 parent 596bb27 commit 2506976

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/Command/Cache/AbstractCacheCommand.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Ymir\Cli\Command\Cache;
1515

16+
use Illuminate\Support\Collection;
1617
use Symfony\Component\Console\Exception\RuntimeException;
1718
use Ymir\Cli\Command\AbstractCommand;
1819
use Ymir\Cli\Exception\InvalidInputException;
@@ -43,4 +44,14 @@ protected function determineCache(string $question): array
4344

4445
return $cache;
4546
}
47+
48+
/**
49+
* Get the descriptions of the cache types for a given provider and engine.
50+
*/
51+
protected function getCacheTypeDescriptions(int $providerId, string $engine): Collection
52+
{
53+
return $this->apiClient->getCacheTypes($providerId)->map(function (array $details) use ($engine) {
54+
return sprintf('%s vCPU, %sGiB RAM (~$%s/month)', $details['cpu'], $details['ram'], $details['price'][$engine]);
55+
});
56+
}
4657
}

src/Command/Cache/CreateCacheCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
use Symfony\Component\Console\Exception\RuntimeException;
1818
use Symfony\Component\Console\Input\InputArgument;
1919
use Symfony\Component\Console\Input\InputOption;
20-
use Ymir\Cli\Command\AbstractCommand;
2120
use Ymir\Cli\Exception\CommandCancelledException;
2221
use Ymir\Cli\Exception\InvalidInputException;
2322
use Ymir\Cli\Project\Configuration\CacheConfigurationChange;
2423

25-
class CreateCacheCommand extends AbstractCommand
24+
class CreateCacheCommand extends AbstractCacheCommand
2625
{
2726
/**
2827
* The name of the command.
@@ -88,9 +87,7 @@ private function determineType(Collection $network, string $engine): string
8887
}
8988

9089
$type = $this->input->getStringOption('type');
91-
$types = $this->apiClient->getCacheTypes((int) $network['provider']['id'])->map(function (array $details) use ($engine) {
92-
return sprintf('%s vCPU, %sGiB RAM (~$%s/month)', $details['cpu'], $details['ram'], $details['price'][$engine]);
93-
});
90+
$types = $this->getCacheTypeDescriptions((int) $network['provider']['id'], $engine);
9491

9592
if (null !== $type && !$types->has($type)) {
9693
throw new InvalidInputException(sprintf('The type "%s" isn\'t a valid cache cluster type', $type));

src/Command/Cache/ModifyCacheCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function perform()
4545
{
4646
$cache = $this->determineCache('Which cache cluster would you like to modify');
4747
$type = $this->input->getStringOption('type', true);
48-
$types = $this->apiClient->getCacheTypes($cache['provider']['id']);
48+
$types = $this->getCacheTypeDescriptions($cache['provider']['id'], $cache['engine']);
4949

5050
if (null === $type) {
5151
$type = $this->output->choice(sprintf('What should the cache cluster type be changed to? <fg=default>(Currently: <comment>%s</comment>)</>', $cache['type']), $types);

0 commit comments

Comments
 (0)