Skip to content

Commit 3d84c62

Browse files
authored
Merge pull request #182 from danielebarbaro/feature/list-option--networking
Simplify the List of Takeout Containers
2 parents 4c4c947 + e932f8f commit 3d84c62

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

app/Commands/HelpCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HelpCommand extends Command
1818
'start {container}' => 'Start the provided stopped containers (by ID)',
1919
'stop' => 'Stop a running container from a list of options (optionally pass --all flag)',
2020
'stop {container}' => 'Stop the provided running containers (by ID)',
21-
'list' => 'List all enabled services (optionally pass --json flag)',
21+
'list' => 'List all enabled services (optionally pass --json or --networking flag)',
2222
'logs {container}' => 'Display container logs (by ID)',
2323
];
2424

app/Commands/ListCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class ListCommand extends Command
1111
{
1212
use InitializesCommands;
1313

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

1717
public function handle(Docker $docker): void
1818
{
1919
$this->initializeCommand();
2020

21-
$containersCollection = $docker->takeoutContainers();
21+
$containersCollection = $docker->takeoutContainers(boolval($this->option('networking')));
2222

2323
if ($this->option('json')) {
2424
$this->line($containersCollection->map(function ($item) {

app/Shell/Docker.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,12 @@ public function allContainers(): Collection
9898
);
9999
}
100100

101-
public function takeoutContainers(): Collection
101+
public function takeoutContainers(bool $withNetworking = false): Collection
102102
{
103-
$process = sprintf(
104-
'docker ps -a --filter "name=TO-" --format "table %s|%s"',
105-
'{{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}',
106-
'{{.Label \"com.tighten.takeout.Base_Alias\"}}|{{.Label \"com.tighten.takeout.Full_Alias\"}}'
107-
);
108-
109-
return $this->runAndParseTable($process);
103+
return $this->runAndParseTable(sprintf(
104+
'docker ps -a --filter \'name=TO-\' --format \'table {{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}%s\'',
105+
$withNetworking ? '|{{.Label "com.tighten.takeout.Base_Alias"}}|{{.Label "com.tighten.takeout.Full_Alias"}}' : '',
106+
));
110107
}
111108

112109
public function startableTakeoutContainers(): Collection

0 commit comments

Comments
 (0)