Skip to content

Commit

Permalink
feat: add cache:modify command
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed Feb 6, 2024
1 parent be33e42 commit 50dfd44
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"symfony/polyfill-php80": "^1.27",
"symfony/process": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0",
"ymirapp/ymir-sdk-php": "^1.0.0"
"ymirapp/ymir-sdk-php": "^1.1.0"
},
"require-dev": {
"fakerphp/faker": "^1.17",
Expand Down
8 changes: 8 additions & 0 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ public function startDeployment(int $deploymentId)
$this->client->startDeployment($deploymentId);
}

/**
* Update the given cache cluster.
*/
public function updateCache(int $cacheId, string $type)
{
$this->client->updateCache($cacheId, $type);
}

/**
* Update the given database server.
*/
Expand Down
66 changes: 66 additions & 0 deletions src/Command/Cache/ModifyCacheCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

/*
* This file is part of Ymir command-line tool.
*
* (c) Carl Alexander <support@ymirapp.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ymir\Cli\Command\Cache;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Ymir\Cli\Console\Input;
use Ymir\Cli\Console\Output;
use Ymir\Cli\Exception\InvalidInputException;

class ModifyCacheCommand extends AbstractCacheCommand
{
/**
* The name of the command.
*
* @var string
*/
public const NAME = 'cache:modify';

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName(self::NAME)
->setDescription('Modify a cache cluster')
->addArgument('cache', InputArgument::OPTIONAL, 'The ID or name of the cache cluster to modify')
->addOption('type', null, InputOption::VALUE_REQUIRED, 'The cache cluster type');
}

/**
* {@inheritdoc}
*/
protected function perform(Input $input, Output $output)
{
$cache = $this->determineCache('Which cache cluster would you like to modify', $input, $output);
$type = $input->getStringOption('type', true);
$types = $this->apiClient->getCacheTypes($cache['provider']['id']);

if (null === $type) {
$type = $output->choice(sprintf('What should the cache cluster type be changed to? <fg=default>(Currently: <comment>%s</comment>)</>', $cache['type']), $types);
} elseif (!$types->has($type)) {
throw new InvalidInputException(sprintf('The type "%s" isn\'t a valid cache cluster type', $type));
}

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)) {
exit;
}

$this->apiClient->updateCache((int) $cache['id'], $type);

$output->infoWithDelayWarning('Cache cluster modified');
}
}

0 comments on commit 50dfd44

Please sign in to comment.