Skip to content

Commit

Permalink
update commands
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Jan 2, 2024
1 parent ebf91d2 commit 18851a1
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"require-dev": {
"workerman/webman-framework": "^1.0",
"symfony/var-dumper": "^6.0",
"phpunit/phpunit": "^9.6"
"phpunit/phpunit": "^9.6",
"webman/console": "^1.0"
},
"suggest": {
"webman/console": "Webman-CLI support. "
},
"autoload": {
"psr-4": {
Expand Down
27 changes: 27 additions & 0 deletions src/Commands/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);

namespace Workbunny\WebmanSharedCache\Commands;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;

abstract class AbstractCommand extends Command
{

protected function info(OutputInterface $output, string $message): void
{
$output->writeln("ℹ️ $message");
}

protected function error(OutputInterface $output, string $message): int
{
$output->writeln("$message");
return self::FAILURE;
}

protected function success(OutputInterface $output, string $message): int
{
$output->writeln("$message");
return self::SUCCESS;
}
}
32 changes: 32 additions & 0 deletions src/Commands/WorkbunnyWebmanSharedCacheClean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace Workbunny\WebmanSharedCache\Commands;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Workbunny\WebmanSharedCache\Cache;

class WorkbunnyWebmanSharedCacheClean extends AbstractCommand
{
/**
* @return void
*/
protected function configure(): void
{
$this->setName('workbunny:shared-cache-clean')
->setDescription('Remove all workbunny/webman-shared-cache caches. ');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
Cache::Clear();
return $this->success($output, "All caches removed successfully. ");
}
}
44 changes: 44 additions & 0 deletions src/Commands/WorkbunnyWebmanSharedCacheList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace Workbunny\WebmanSharedCache\Commands;

use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class WorkbunnyWebmanSharedCacheList extends AbstractCommand
{
/**
* @return void
*/
protected function configure(): void
{
$this->setName('workbunny:shared-cache-list')
->setDescription('Show workbunny/webman-shared-cache caches list. ');

$this->addOption('page', 'p', InputOption::VALUE_OPTIONAL, 'Page. ', 1);
$this->addOption('size', 's', InputOption::VALUE_OPTIONAL, 'Page size. ', 20);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$page = $input->getOption('page');
$size = $input->getOption('size');
$headers = ['name', 'value'];
$rows = [];
// todo

$table = new Table($output);
$table->setHeaders($headers);
$table->setRows($rows);
$table->render();

return self::SUCCESS;
}
}

0 comments on commit 18851a1

Please sign in to comment.