Skip to content

Commit

Permalink
Merge pull request #182 from danielebarbaro/feature/list-option--netw…
Browse files Browse the repository at this point in the history
…orking

Simplify the List of Takeout Containers
  • Loading branch information
tonysm authored Jan 3, 2025
2 parents 4c4c947 + e932f8f commit 3d84c62
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
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')));

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
{
$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

0 comments on commit 3d84c62

Please sign in to comment.