Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add categories on json list #149

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Commands;

use App\InitializesCommands;
use App\Services\Category;
use App\Shell\Docker;
use LaravelZero\Framework\Commands\Command;

Expand All @@ -20,7 +21,10 @@ public function handle(): void
$containersCollection = app(Docker::class)->takeoutContainers();

if ($this->option('json')) {
$this->line($containersCollection->toJson());
$this->line($containersCollection->map(function ($item) {
$item['category'] = Category::fromContainerName($item['names']);
return $item;
})->toJson());
return;
}

Expand Down
28 changes: 28 additions & 0 deletions app/Services/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Services;

use App\Services;

abstract class Category
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this has been sitting open for ages so I'm sorry to make one more request, but could you write tests for these two new methods?

Thanks so much!

{
const CACHE = 'Cache';
Expand All @@ -10,4 +12,30 @@ abstract class Category
const SEARCH = 'Search';
const STORAGE = 'Storage';
const TOOLS = 'Tools';

public static function all(): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would more be a method on the Service class named allByCategory or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all() now returns:

$result = [
    'beanstalkd' => "Cache",
    'clickhouse' => "Database",
    'dynamodb' => "Cache",
    'elasticsearch' => "Search",
    'eventstoredb' => "Database",
    'expose' => "Tools",
    'influxdb' => "Database",
    'mailhog' => "Mail",
    'mariadb' => "Database",
    'meilisearch' => "Search",
    'memcached' => "Cache",
    'minio' => "Storage",
    'mongo' => "Database",
    'mssql' => "Database",
    'mysql' => "Database",
    'neo4j' => "Database",
    'postgis' => "Database",
    'postgresql' => "Database",
    'redis' => "Cache",
    'sftp' => "Storage",
    'sqs' => "Cache"
];

so the right name (for me) is mapByService()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I still think this is more of a list of services than a list of categories, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops sorry 🙈 I misunderstood!
Apologies, you're right, it is a method for Service class.

{
return collect((new Services)->all())
->mapWithKeys(function ($fqcn, $shortName) {
return [$shortName => $fqcn::category()];
})
->toArray();
}

public static function get(string $serviceName): string
danielebarbaro marked this conversation as resolved.
Show resolved Hide resolved
{
$servicesByCategory = self::all();
return array_key_exists($serviceName, $servicesByCategory) ? strtolower($servicesByCategory[$serviceName]) : 'other';
}

public static function fromContainerName(string $containerName): string
{
$serviceName = array_slice(
explode('--', $containerName),
1,
1
);
$serviceName = reset($serviceName);
return self::get($serviceName);
}
}