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 all 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 containers (by ID)',
'stop' => 'Stop a running container from a list of options (optionally pass --all flag)',
'stop {container}' => 'Stop the provided running containers (by ID)',
'list' => 'List all enabled services (optionally pass --json flag)',
'list' => 'List all enabled services (optionally pass --json or --networking flag)',
'logs {container}' => 'Display container logs (by ID)',
];

Expand Down
4 changes: 2 additions & 2 deletions app/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ 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(Docker $docker): void
{
$this->initializeCommand();

$containersCollection = $docker->takeoutContainers();
$containersCollection = $docker->takeoutContainers(boolval($this->option('networking')));
gcavanunez marked this conversation as resolved.
Show resolved Hide resolved

if ($this->option('json')) {
$this->line($containersCollection->map(function ($item) {
Expand Down
13 changes: 5 additions & 8 deletions app/Shell/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,12 @@ public function allContainers(): Collection
);
}

public function takeoutContainers(): Collection
public function takeoutContainers(bool $withNetworking = false): Collection
gcavanunez marked this conversation as resolved.
Show resolved Hide resolved
{
$process = sprintf(
'docker ps -a --filter "name=TO-" --format "table %s|%s"',
'{{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}',
'{{.Label \"com.tighten.takeout.Base_Alias\"}}|{{.Label \"com.tighten.takeout.Full_Alias\"}}'
);

return $this->runAndParseTable($process);
return $this->runAndParseTable(sprintf(
'docker ps -a --filter \'name=TO-\' --format \'table {{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}%s\'',
$withNetworking ? '|{{.Label "com.tighten.takeout.Base_Alias"}}|{{.Label "com.tighten.takeout.Full_Alias"}}' : '',
));
}

public function startableTakeoutContainers(): Collection
Expand Down
Loading