Skip to content

Commit 50dfd44

Browse files
committed
feat: add cache:modify command
1 parent be33e42 commit 50dfd44

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/polyfill-php80": "^1.27",
3333
"symfony/process": "^5.4|^6.0",
3434
"symfony/yaml": "^5.4|^6.0",
35-
"ymirapp/ymir-sdk-php": "^1.0.0"
35+
"ymirapp/ymir-sdk-php": "^1.1.0"
3636
},
3737
"require-dev": {
3838
"fakerphp/faker": "^1.17",

src/ApiClient.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,14 @@ public function startDeployment(int $deploymentId)
777777
$this->client->startDeployment($deploymentId);
778778
}
779779

780+
/**
781+
* Update the given cache cluster.
782+
*/
783+
public function updateCache(int $cacheId, string $type)
784+
{
785+
$this->client->updateCache($cacheId, $type);
786+
}
787+
780788
/**
781789
* Update the given database server.
782790
*/
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of Ymir command-line tool.
7+
*
8+
* (c) Carl Alexander <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Ymir\Cli\Command\Cache;
15+
16+
use Symfony\Component\Console\Input\InputArgument;
17+
use Symfony\Component\Console\Input\InputOption;
18+
use Ymir\Cli\Console\Input;
19+
use Ymir\Cli\Console\Output;
20+
use Ymir\Cli\Exception\InvalidInputException;
21+
22+
class ModifyCacheCommand extends AbstractCacheCommand
23+
{
24+
/**
25+
* The name of the command.
26+
*
27+
* @var string
28+
*/
29+
public const NAME = 'cache:modify';
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
protected function configure()
35+
{
36+
$this
37+
->setName(self::NAME)
38+
->setDescription('Modify a cache cluster')
39+
->addArgument('cache', InputArgument::OPTIONAL, 'The ID or name of the cache cluster to modify')
40+
->addOption('type', null, InputOption::VALUE_REQUIRED, 'The cache cluster type');
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected function perform(Input $input, Output $output)
47+
{
48+
$cache = $this->determineCache('Which cache cluster would you like to modify', $input, $output);
49+
$type = $input->getStringOption('type', true);
50+
$types = $this->apiClient->getCacheTypes($cache['provider']['id']);
51+
52+
if (null === $type) {
53+
$type = $output->choice(sprintf('What should the cache cluster type be changed to? <fg=default>(Currently: <comment>%s</comment>)</>', $cache['type']), $types);
54+
} elseif (!$types->has($type)) {
55+
throw new InvalidInputException(sprintf('The type "%s" isn\'t a valid cache cluster type', $type));
56+
}
57+
58+
if (!$output->confirm('Modifying the cache cluster will cause your cache cluster to become unavailable for a few minutes. Do you want to proceed?', false)) {
59+
exit;
60+
}
61+
62+
$this->apiClient->updateCache((int) $cache['id'], $type);
63+
64+
$output->infoWithDelayWarning('Cache cluster modified');
65+
}
66+
}

0 commit comments

Comments
 (0)