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

Simplify the List of Takeout Containers #182

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion app/Commands/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HelpCommand extends Command
'start {container}' => 'Start the provided stopped container (by ID)',
'stop' => 'Stop a running container from a list of options',
'stop {container}' => 'Stop the provided running container (by ID)',
'list' => 'List all enabled services (optionally pass --json flag)',
'list' => 'List all enabled services (optionally pass --json or --networking flags)',
'logs {container}' => 'Display container logs (by ID)',
];

Expand Down
16 changes: 14 additions & 2 deletions app/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ class ListCommand extends Command
{
use InitializesCommands;

protected $signature = 'list {--json}';
protected $signature = 'list {--json}{--networking}';
protected $description = 'List all services enabled by Takeout.';

public function handle(): void
{
$this->initializeCommand();

$containersCollection = app(Docker::class)->takeoutContainers();
$docker = app(Docker::class);

$containersCollection = $docker->takeoutContainers();

if ($this->option('json')) {
$this->line($containersCollection->toJson());
Expand All @@ -29,6 +31,16 @@ public function handle(): void
return;
}

if ($this->option('networking')) {
$takeoutNetworkContainers = $docker->takeoutNetworkContainers();

$containers = $takeoutNetworkContainers->toArray();
$columns = array_map('App\title_from_slug', array_keys(reset($containers)));

$this->table($columns, $containers);
return;
}

$containers = $containersCollection->toArray();
$columns = array_map('App\title_from_slug', array_keys(reset($containers)));

Expand Down
7 changes: 7 additions & 0 deletions app/Shell/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public function allContainers(): Collection
}

public function takeoutContainers(): Collection
{
return $this->runAndParseTable(
"docker ps -a --filter 'name=TO-' --format 'table {{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}'"
);
}

public function takeoutNetworkContainers(): Collection
tonysm marked this conversation as resolved.
Show resolved Hide resolved
{
$process = sprintf(
"docker ps -a --filter 'name=TO-' --format 'table %s|%s'",
Expand Down